@@ -160,12 +160,15 @@ def _inner_end(*args: "P.args", **kwargs: "P.kwargs") -> "T":
160160
161161 if query is not None and breadcrumb_data is not None :
162162 client_options = sentry_sdk .get_client ().options
163- if (
164- has_data_collection_enabled (client_options )
165- and client_options ["data_collection" ]["database_query_data" ]
166- ) or (
167- not has_data_collection_enabled (client_options )
168- and should_send_default_pii ()
163+ if res is not None and (
164+ (
165+ has_data_collection_enabled (client_options )
166+ and client_options ["data_collection" ]["database_query_data" ]
167+ )
168+ or (
169+ not has_data_collection_enabled (client_options )
170+ and should_send_default_pii ()
171+ )
169172 ):
170173 breadcrumb_data = {"db.result" : res , ** breadcrumb_data }
171174
@@ -237,6 +240,9 @@ def wrapped_generator() -> "Iterator[Any]":
237240 data = wrapped_generator ()
238241
239242 span .set_data ("db.params" , db_params )
243+ breadcrumb_data = getattr (self .connection , "_breadcrumb_data" , None )
244+ if breadcrumb_data is not None :
245+ breadcrumb_data ["db.params" ] = db_params
240246 elif should_send_default_pii ():
241247 db_params = span ._data .get ("db.params" , [])
242248
@@ -258,6 +264,9 @@ def wrapped_generator() -> "Iterator[Any]":
258264 data = wrapped_generator ()
259265
260266 span .set_data ("db.params" , db_params )
267+ breadcrumb_data = getattr (self .connection , "_breadcrumb_data" , None )
268+ if breadcrumb_data is not None :
269+ breadcrumb_data ["db.params" ] = db_params
261270
262271 return original_send_data (
263272 self , sample_block , data , types_check , columnar , * args , ** kwargs
0 commit comments