Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
marsha97 opened this issue May 20, 2024 · 4 comments · Fixed by #3096
Closed

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

marsha97 opened this issue May 20, 2024 · 4 comments · Fixed by #3096
Assignees
Labels

Comments

@marsha97
Copy link

marsha97 commented May 20, 2024

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'
>>> 
@marsha97 marsha97 changed the title Clickhouse integration not working after upgrading from 1.45.0 [Django] Clickhouse integration not working after upgrading from 1.45.0 May 20, 2024
@sentrivana
Copy link
Contributor

sentrivana commented May 21, 2024

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

@sentrivana
Copy link
Contributor

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).

@marsha97
Copy link
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

@sentrivana
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants