16
16
except ImportError :
17
17
from django .core .urlresolvers import reverse
18
18
19
- from sentry_sdk import capture_message , capture_exception
19
+ from sentry_sdk import capture_message , capture_exception , configure_scope
20
20
from sentry_sdk .integrations .django import DjangoIntegration
21
21
22
22
from tests .integrations .django .myapp .wsgi import application
@@ -182,16 +182,13 @@ def test_sql_queries(sentry_init, capture_events, with_integration):
182
182
183
183
from django .db import connection
184
184
185
- sentry_init (
186
- integrations = [DjangoIntegration ()],
187
- send_default_pii = True ,
188
- _experiments = {"record_sql_params" : True },
189
- )
190
-
191
185
events = capture_events ()
192
186
193
187
sql = connection .cursor ()
194
188
189
+ with configure_scope () as scope :
190
+ scope .clear_breadcrumbs ()
191
+
195
192
with pytest .raises (OperationalError ):
196
193
# table doesn't even exist
197
194
sql .execute ("""SELECT count(*) FROM people_person WHERE foo = %s""" , [123 ])
@@ -201,7 +198,7 @@ def test_sql_queries(sentry_init, capture_events, with_integration):
201
198
(event ,) = events
202
199
203
200
if with_integration :
204
- crumb = event ["breadcrumbs" ][- 1 ]
201
+ crumb = event ["breadcrumbs" ]["values" ][ - 1 ]
205
202
206
203
assert crumb ["message" ] == "SELECT count(*) FROM people_person WHERE foo = %s"
207
204
assert crumb ["data" ]["db.params" ] == [123 ]
@@ -224,6 +221,9 @@ def test_sql_dict_query_params(sentry_init, capture_events):
224
221
sql = connections ["postgres" ].cursor ()
225
222
226
223
events = capture_events ()
224
+ with configure_scope () as scope :
225
+ scope .clear_breadcrumbs ()
226
+
227
227
with pytest .raises (ProgrammingError ):
228
228
sql .execute (
229
229
"""SELECT count(*) FROM people_person WHERE foo = %(my_foo)s""" ,
@@ -233,7 +233,7 @@ def test_sql_dict_query_params(sentry_init, capture_events):
233
233
capture_message ("HI" )
234
234
(event ,) = events
235
235
236
- crumb = event ["breadcrumbs" ][- 1 ]
236
+ crumb = event ["breadcrumbs" ]["values" ][ - 1 ]
237
237
assert crumb ["message" ] == (
238
238
"SELECT count(*) FROM people_person WHERE foo = %(my_foo)s"
239
239
)
@@ -266,14 +266,18 @@ def test_sql_psycopg2_string_composition(sentry_init, capture_events, query):
266
266
267
267
sql = connections ["postgres" ].cursor ()
268
268
269
+ with configure_scope () as scope :
270
+ scope .clear_breadcrumbs ()
271
+
269
272
events = capture_events ()
273
+
270
274
with pytest .raises (ProgrammingError ):
271
275
sql .execute (query (psycopg2 .sql ), {"my_param" : 10 })
272
276
273
277
capture_message ("HI" )
274
278
275
279
(event ,) = events
276
- crumb = event ["breadcrumbs" ][- 1 ]
280
+ crumb = event ["breadcrumbs" ]["values" ][ - 1 ]
277
281
assert crumb ["message" ] == ('SELECT %(my_param)s FROM "foobar"' )
278
282
assert crumb ["data" ]["db.params" ] == {"my_param" : 10 }
279
283
@@ -296,6 +300,9 @@ def test_sql_psycopg2_placeholders(sentry_init, capture_events):
296
300
sql = connections ["postgres" ].cursor ()
297
301
298
302
events = capture_events ()
303
+ with configure_scope () as scope :
304
+ scope .clear_breadcrumbs ()
305
+
299
306
with pytest .raises (DataError ):
300
307
names = ["foo" , "bar" ]
301
308
identifiers = [psycopg2 .sql .Identifier (name ) for name in names ]
@@ -313,10 +320,10 @@ def test_sql_psycopg2_placeholders(sentry_init, capture_events):
313
320
capture_message ("HI" )
314
321
315
322
(event ,) = events
316
- for crumb in event ["breadcrumbs" ]:
323
+ for crumb in event ["breadcrumbs" ][ "values" ] :
317
324
del crumb ["timestamp" ]
318
325
319
- assert event ["breadcrumbs" ][- 2 :] == [
326
+ assert event ["breadcrumbs" ]["values" ][ - 2 :] == [
320
327
{
321
328
"category" : "query" ,
322
329
"data" : {"db.paramstyle" : "format" },
0 commit comments