Skip to content

clickhouse-driver integration eats inserted data when generator is used #4657

Closed

Description

@beda42

How do you use Sentry?

Self-hosted/on-premise

Version

2.34.1

Steps to Reproduce

In a Django project using clickhouse-driver (0.2.9) to interact with an external database I recently upgraded sentry sdk. Inserting data into clickhouse stopped working afterward. The reason was that we are using a generator as a source of data for the INSERT query and the sentry clickhouse-driver integration consumes the generator before it is passed to the clickhouse-driver. Thus an INSERT is sent to clickhouse with empty data.

This is a barebones example where using a generator to pass the data results in no data being written to the database.

records = [{"aa": 1, "bb": 2}]
data = (rec for rec in records)  # generator
client.execute("INSERT INTO XXX (aa, bb) VALUES ", data)

When I replaced the generator with a generator which would throw an Exception, I got the following traceback:

  File "/opt/virtualenvs/celus/lib/python3.12/site-packages/clickhouse_driver/client.py", line 376, in execute
    rv = self.process_insert_query(

  File "/opt/virtualenvs/celus/lib/python3.12/site-packages/clickhouse_driver/client.py", line 607, in process_insert_query
    rv = self.send_data(sample_block, data,
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/virtualenvs/celus/lib/python3.12/site-packages/sentry_sdk/integrations/clickhouse_driver.py", line 142, in _inner_send_data
    db_params.extend(data)
    ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/virtualenvs/celus/lib/python3.12/site-packages/hcube/backends/clickhouse/backend.py", line 64, in ff
    raise ValueError('sh*t, someone ate my data')
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Which shows the point where the generator gets consumed.

Expected Result

Data being written to clickhouse.

Actual Result

No data being written into clickhouse.

Activity

  1. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Aug 3, 2025
  2. szokeasaurusrex commented on Aug 4, 2025

    @szokeasaurusrex
    Member

    Hi @beda42, thank you for reporting this issue.

    I was able to reproduce the behavior you observed, and it indeed appears to be a bug, which occurs when send_default_pii=True is set in your sentry_sdk.init call. As a temporary workaround while you wait for a fix, you can set send_default_pii=False in sentry_sdk.init (or you can remove the configuration, as the default is False when the parameter is missing).

  3. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Aug 4, 2025
  4. added 4 commits that reference this issue on Aug 4, 2025
    c203bb6
    3e3bd5e
    e38354b
    d9ee8c8
  5. added a commit that references this issue on Aug 7, 2025
    3ef02a1
  6. added a commit that references this issue on Aug 12, 2025
    fac580d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions