Skip to content

fix(async): parsing query response with two-bytes UTF-8 character #518

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

Merged
merged 2 commits into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

### Bug Fixes
1. [#512](https://github.com/influxdata/influxdb-client-python/pull/512): Exception propagation for asynchronous `QueryApi` [async/await]
1. [#518](https://github.com/influxdata/influxdb-client-python/pull/518): Parsing query response with two-bytes UTF-8 character [async/await]

## 1.33.0 [2022-09-29]

Expand Down
6 changes: 5 additions & 1 deletion influxdb_client/client/flux_csv_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,10 @@ def _print_profiler_info(self, flux_record: FluxRecord):
class _StreamReaderToWithAsyncRead:
def __init__(self, response):
self.response = response
self.decoder = codecs.getincrementaldecoder(_UTF_8_encoding)()

async def read(self, size: int) -> str:
return (await self.response.read(size)).decode(_UTF_8_encoding)
raw_bytes = (await self.response.read(size))
if not raw_bytes:
return self.decoder.decode(b'', final=True)
return self.decoder.decode(raw_bytes, final=False)
19 changes: 19 additions & 0 deletions tests/test_InfluxDBClientAsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,25 @@ async def test_query_exception_propagation(self):
await self.client.query_api().query("buckets()", "my-org")
self.assertEqual("unauthorized access", e.value.message)

@async_test
@aioresponses()
async def test_parse_utf8_two_bytes_character(self, mocked):
await self.client.close()
self.client = InfluxDBClientAsync("http://localhost")

body = '''#group,false,false,false,false,true,true,true
#datatype,string,long,dateTime:RFC3339,string,string,string,string
#default,_result,,,,,,
,result,table,_time,_value,_field,_measurement,type
'''
for i in range(1000):
body += f",,0,2022-10-13T12:28:31.{i}Z,ÂÂÂ,value,async,error\n"

mocked.post('http://localhost/api/v2/query?org=my-org', status=200, body=body)

data_frame = await self.client.query_api().query_data_frame("from()", "my-org")
self.assertEqual(1000, len(data_frame))

async def _prepare_data(self, measurement: str):
_point1 = Point(measurement).tag("location", "Prague").field("temperature", 25.3)
_point2 = Point(measurement).tag("location", "New York").field("temperature", 24.3)
Expand Down