Skip to content

Commit f024155

Browse files
committed
fix: return str instead of urllib3.HTTPResponse for InfluxDBClient.QueryAPI.query_raw
1 parent 2f9e5ed commit f024155

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

CHANGELOG.md

+21
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,32 @@
11
## 1.39.0 [unreleased]
22

3+
### Breaking Changes
4+
5+
1. [#569](https://github.com/influxdata/influxdb-client-python/pull/569): Return `str` instead of `urllib3.HTTPResponse` for `InfluxDBClient.QueryAPI.query_raw`.
6+
7+
This fixes `InfluxDBClient.query_raw` that returned the wrong type based on the documentation.
8+
The `AsyncInfluxDBClient` is not affected.
9+
10+
To make your code compatible with this version, you can remove the step of retrieving the response content:
11+
12+
```python
13+
from influxdb_client.client import InfluxDBClient
14+
15+
with InfluxDBClient(url="http://localhost:8086", token="my-token", org="my-org") as client:
16+
query = "..."
17+
result = client.query_raw(query=query)
18+
- content = result.data.decode("utf8")
19+
+ content = result
20+
```
21+
22+
323
## 1.38.0 [2023-10-02]
424

525
### Bug Fixes
626
1. [#601](https://github.com/influxdata/influxdb-client-python/pull/601): Use HTTResponse.headers to clear deprecation warning [urllib3]
727
1. [#610](https://github.com/influxdata/influxdb-client-python/pull/601): Use iloc to clear deprecation warning
828

29+
930
### Documentation
1031
1. [#566](https://github.com/influxdata/influxdb-client-python/pull/566): Fix Sphinx documentation build and add support `.readthedocs.yml` V2 configuration file
1132

influxdb_client/client/query_api.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from influxdb_client import Dialect
1010
from influxdb_client.client._base import _BaseQueryApi
1111
from influxdb_client.client.flux_table import FluxRecord, TableList, CSVIterator
12+
from influxdb_client.rest import _UTF_8_encoding
1213

1314

1415
class QueryOptions(object):
@@ -121,8 +122,8 @@ def query_raw(self, query: str, org=None, dialect=_BaseQueryApi.default_dialect,
121122
org = self._org_param(org)
122123
result = self._query_api.post_query(org=org, query=self._create_query(query, dialect, params), async_req=False,
123124
_preload_content=False)
124-
125-
return result
125+
raw_bytes = result.data
126+
return raw_bytes.decode(_UTF_8_encoding)
126127

127128
def query(self, query: str, org=None, params: dict = None) -> TableList:
128129
"""Execute synchronous Flux query and return result as a :class:`~influxdb_client.client.flux_table.FluxTable` list.

tests/test_InfluxDBClient.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import codecs
21
import http.server
32
import json
43
import logging
@@ -346,7 +345,8 @@ def test_query_and_debug(self):
346345
self.assertIn("my-bucket", list(map(lambda record: record["name"], results[0].records)))
347346
# Query RAW
348347
results = self.client.query_api().query_raw("buckets()", "my-org")
349-
self.assertIn("my-bucket", codecs.decode(results.data))
348+
self.assertIn("my-bucket", results)
349+
self.assertTrue(isinstance(results, str))
350350
# Bucket API
351351
results = self.client.buckets_api().find_buckets()
352352
self.assertIn("my-bucket", list(map(lambda bucket: bucket.name, results.buckets)))

0 commit comments

Comments
 (0)