Skip to content

Commit 38c14e9

Browse files
authored
fix(clickhouse): _sentry_span might be missing (#3096)
We started auto-enabling the ClickHouse integration in 2.0+. This led to it getting auto-enabled also for folks using ClickHouse with Django via `django-clickhouse-backend`, but it turns out that the integration doesn't work properly with `django-clickhouse-backend` and leads to `AttributeError: 'Connection' object has no attribute '_sentry_span'`.
1 parent 7af75ce commit 38c14e9

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

sentry_sdk/integrations/clickhouse_driver.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def _wrap_end(f: Callable[P, T]) -> Callable[P, T]:
107107
def _inner_end(*args: P.args, **kwargs: P.kwargs) -> T:
108108
res = f(*args, **kwargs)
109109
instance = args[0]
110-
span = instance.connection._sentry_span # type: ignore[attr-defined]
110+
span = getattr(instance.connection, "_sentry_span", None) # type: ignore[attr-defined]
111111

112112
if span is not None:
113113
if res is not None and should_send_default_pii():
@@ -129,14 +129,15 @@ def _wrap_send_data(f: Callable[P, T]) -> Callable[P, T]:
129129
def _inner_send_data(*args: P.args, **kwargs: P.kwargs) -> T:
130130
instance = args[0] # type: clickhouse_driver.client.Client
131131
data = args[2]
132-
span = instance.connection._sentry_span
132+
span = getattr(instance.connection, "_sentry_span", None)
133133

134-
_set_db_data(span, instance.connection)
134+
if span is not None:
135+
_set_db_data(span, instance.connection)
135136

136-
if should_send_default_pii():
137-
db_params = span._data.get("db.params", [])
138-
db_params.extend(data)
139-
span.set_data("db.params", db_params)
137+
if should_send_default_pii():
138+
db_params = span._data.get("db.params", [])
139+
db_params.extend(data)
140+
span.set_data("db.params", db_params)
140141

141142
return f(*args, **kwargs)
142143

0 commit comments

Comments
 (0)