long2ice / asynch

An asyncio ClickHouse Python Driver with native (TCP) interface support.
https://github.com/long2ice/asynch
Apache License 2.0
185 stars 43 forks source link

Streaming queries fail when user is readonly type 1 #67

Open frabarz opened 1 year ago

frabarz commented 1 year ago

I'm using a database where I don't have access to the user settings. The provided user has a readonly profile with the <readonly>1</readonly> setting. I'm using a Cursor with _stream_results set to True and not modifying the default _max_row_buffer value. When executing the query, the server returns this error:

Code: 164.
DB::Exception: Cannot modify 'max_block_size' setting in readonly mode

One solution would be change the user readonly setting to <readonly>2</readonly>, which allows using settings, but I can't do that. The other is simply not sending settings with the query. Looking at the source of Cursor._prepare, it always sets the "max_block_size" key in the settings when _stream_results is True. When I commented this line and tried again, the query executed without issues.

I'm wondering if there's a way to avoid using settings by passing a parameter or maybe reading the connection string, since it's something directly related to the user used in it. Clickhouse used to have the ?readonly=2 connection parameter, but I think it was removed some versions ago.