Skip to content

[Django] Clickhouse integration not working after upgrading from 1.45.0 #3088

Closed

Description

@marsha97

How do you use Sentry?

Sentry Saas (sentry.io)

Version

2.2.0

Steps to Reproduce

I tried to query as usual with django-clickhouse-backend
as simple as CHFoo.objects.first()

and I got AttributeError: 'Connection' object has no attribute '_sentry_span' exception.

It worked before when using version 1.45.0

I have tried to bump the clickhouse-driver and django-clickhouse-backend, bu no luck

pip:

sentry-sdk==2.2.0
clickhouse-driver==0.2.7
clickhouse-pool==0.5.3
django-clickhouse-backend==1.1.7

Expected Result

Should work as usual

Actual Result

>>> CHVoucher.objects.first()
Traceback (most recent call last):
  File "<input>", line 1, in <module>
    CHVoucher.objects.first()
  File "/home/marsha/venv/stamps/lib/python3.10/site-packages/django/db/models/manager.py", line 87, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/home/marsha/venv/stamps/lib/python3.10/site-packages/django/db/models/query.py", line 1057, in first
    for obj in queryset[:1]:
  File "/home/marsha/venv/stamps/lib/python3.10/site-packages/django/db/models/query.py", line 398, in __iter__
    self._fetch_all()
  File "/home/marsha/venv/stamps/lib/python3.10/site-packages/django/db/models/query.py", line 1881, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "/home/marsha/venv/stamps/lib/python3.10/site-packages/django/db/models/query.py", line 91, in __iter__
    results = compiler.execute_sql(
  File "/home/marsha/venv/stamps/lib/python3.10/site-packages/django/db/models/sql/compiler.py", line 1562, in execute_sql
    cursor.execute(sql, params)
  File "/home/marsha/venv/stamps/lib/python3.10/site-packages/django/db/backends/utils.py", line 102, in execute
    return super().execute(sql, params)
  File "/home/marsha/venv/stamps/lib/python3.10/site-packages/sentry_sdk/utils.py", line 1711, in runner
    return sentry_patched_function(*args, **kwargs)
  File "/home/marsha/venv/stamps/lib/python3.10/site-packages/sentry_sdk/integrations/django/__init__.py", line 629, in execute
    result = real_execute(self, sql, params)
  File "/home/marsha/venv/stamps/lib/python3.10/site-packages/django/db/backends/utils.py", line 67, in execute
    return self._execute_with_wrappers(
  File "/home/marsha/venv/stamps/lib/python3.10/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/home/marsha/venv/stamps/lib/python3.10/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
  File "/home/marsha/venv/stamps/lib/python3.10/site-packages/clickhouse_backend/driver/connection.py", line 108, in execute
    super().execute(operation, parameters)
  File "/home/marsha/venv/stamps/lib/python3.10/site-packages/clickhouse_driver/dbapi/cursor.py", line 111, in execute
    response = execute(
  File "/home/marsha/venv/stamps/lib/python3.10/site-packages/clickhouse_backend/driver/client.py", line 53, in execute
    rv = self.process_ordinary_query(
  File "/home/marsha/venv/stamps/lib/python3.10/site-packages/clickhouse_driver/client.py", line 580, in process_ordinary_query
    return self.receive_result(with_column_types=with_column_types,
  File "/home/marsha/venv/stamps/lib/python3.10/site-packages/sentry_sdk/integrations/clickhouse_driver.py", line 109, in _inner_end
    span = instance.connection._sentry_span  # type: ignore[attr-defined]
AttributeError: 'Connection' object has no attribute '_sentry_span'
>>> 

Activity

  1. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on May 20, 2024
  2. changed the title [-]Clickhouse integration not working after upgrading from 1.45.0[/-] [+][Django] Clickhouse integration not working after upgrading from 1.45.0[/+] on May 20, 2024
  3. sentrivana commented on May 21, 2024

    @sentrivana
    Collaborator

    Thanks @marsha97, looks like a possible regression in 2.0, we will take a look asap.

  4. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on May 21, 2024
  5. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on May 21, 2024
  6. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on May 21, 2024
  7. self-assigned this
    on May 22, 2024
  8. sentrivana commented on May 22, 2024

    @sentrivana
    Collaborator

    The reason for this is that in SDK 2.0+ we're now auto-enabling the ClickhouseIntegration if you have clickhouse-driver installed. In most cases this leads to a nicer out-of-the-box experience, but in this case the integration doesn't work properly with django-clickhouse-backend because it starts queries slightly differently compared to vanilla clickhouse-driver.

    In other words, the reason it seemed to work in 1.45.0 is most likely because the integration was not enabled. @marsha97 Correct me if I'm wrong -- you weren't explicitly enabling the integration via integrations=[ClickhouseDriverIntegration()], right?

    Fixing this in #3096 to restore previous behavior (i.e., the integration not actually doing much when used with django-clickhouse-backend). Will roll a release with this tomorrow latest. If anyone needs a workaround until then, you can disable auto enabling integrations and enable the ones you need explicitly.

    We will follow up to actually make this work properly in #3095 (this might take a bit).

  9. marsha97 commented on May 22, 2024

    @marsha97
    Author

    The reason for this is that in SDK 2.0+ we're now auto-enabling the ClickhouseIntegration if you have clickhouse-driver installed. In most cases this leads to a nicer out-of-the-box experience, but in this case the integration doesn't work properly with django-clickhouse-backend because it starts queries slightly differently compared to vanilla clickhouse-driver.

    In other words, the reason it seemed to work in 1.45.0 is most likely because the integration was not enabled. @marsha97 Correct me if I'm wrong -- you weren't explicitly enabling the integration via integrations=[ClickhouseDriverIntegration()], right?

    Fixing this in #3096 to restore previous behavior (i.e., the integration not actually doing much when used with django-clickhouse-backend). Will roll a release with this tomorrow latest. If anyone needs a workaround until then, you can disable auto enabling integrations and enable the ones you need explicitly.

    We will follow up to actually make this work properly in #3095 (this might take a bit).

    Yes, correct, i didn't specify the ch integration explicitly

  10. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on May 22, 2024
  11. sentrivana commented on May 23, 2024

    @sentrivana
    Collaborator

    The fix for this will be out in 2.3.0 later today.

  12. ghost added on Aug 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions