Skip to content

Commit

Permalink
Fix chunked streaming and wait_end_of_query bug
Browse files Browse the repository at this point in the history
  • Loading branch information
genzgd committed Nov 1, 2024
1 parent cb282c9 commit 2843bc7
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ When creating a DBAPI Connection method using the Connection constructor or a SQ
converts any unrecognized keyword argument/query parameter to a ClickHouse server setting. Starting in the next minor
release (0.9.0), unrecognized arguments/keywords for these methods of creating a DBAPI connection will raise an exception
instead of being passed as ClickHouse server settings. This is in conjunction with some refactoring in Client construction.
The supported method of passing ClickHouse server settings is to prefix such arguments/query parameters with`ch_`.
The supported method of passing ClickHouse server settings is to prefix such arguments/query parameters with`ch_`.

## 0.8.6, 2024-11-01
### Bug Fixes
- Correctly stream unchunked HTTP responses. Fixes https://github.com/ClickHouse/clickhouse-connect/issues/417.
- Don't use `wait_end_of_query` for any streaming requests. Fixes https://github.com/ClickHouse/clickhouse-connect/issues/416

## 0.8.5, 2024-10-24
### Bug fix
Expand Down
2 changes: 1 addition & 1 deletion clickhouse_connect/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = '0.8.5'
version = '0.8.6'
2 changes: 1 addition & 1 deletion clickhouse_connect/driver/httpclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ def raw_stream(self, query: str,
See BaseClient doc_string for this method
"""
body, params, fields = self._prep_raw_query(query, parameters, settings, fmt, use_database, external_data)
return self._raw_request(body, params, fields=fields, stream=True)
return self._raw_request(body, params, fields=fields, stream=True, server_wait=False)

def _prep_raw_query(self, query: str,
parameters: Optional[Union[Sequence, Dict[str, Any]]],
Expand Down
2 changes: 1 addition & 1 deletion clickhouse_connect/driver/httputil.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def buffered():
chunks = deque()
done = False
current_size = 0
read_gen = response.read_chunked(chunk_size, decompress is None)
read_gen = response.stream(chunk_size, decompress is None)
while True:
while not done:
chunk = next(read_gen, None) # Always try to read at least one chunk if there are any left
Expand Down
15 changes: 8 additions & 7 deletions clickhouse_connect/driver/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,14 @@ def get_block():
if isinstance(ex, StreamCompleteException):
# We ran out of data before it was expected, this could be ClickHouse reporting an error
# in the response
message = source.last_message
if len(message) > 1024:
message = message[-1024:]
error_start = message.find('Code: ')
if error_start != -1:
message = message[error_start:]
raise StreamFailureError(message) from None
if source.last_message:
message = source.last_message
if len(message) > 1024:
message = message[-1024:]
error_start = message.find('Code: ')
if error_start != -1:
message = message[error_start:]
raise StreamFailureError(message) from None
raise
block_num += 1
return result_block
Expand Down

0 comments on commit 2843bc7

Please sign in to comment.