Skip to content

Commit e291c5e

Browse files
authored
Merge branch 'influxdata:master' into nan-error-field-starting-with-digit
2 parents 521e53a + 4537d21 commit e291c5e

File tree

6 files changed

+54
-9
lines changed

6 files changed

+54
-9
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
:warning: This release drop supports for Python 3.6. As of 2021-12-23, 3.6 has reached the end-of-life phase of its release cycle. 3.6.15 was the final security release. For more info see: https://peps.python.org/pep-0494/#lifespan
44

5+
### Bug Fixes
6+
1. [#483](https://github.com/influxdata/influxdb-client-python/pull/483): Querying data if the `debug` is enabled
7+
1. [#477](https://github.com/influxdata/influxdb-client-python/pull/477): Parsing date fails due to thread race
8+
59
### Dependencies
610
1. [#472](https://github.com/influxdata/influxdb-client-python/pull/472): Update `RxPY` to `4.0.4`
711

influxdb_client/client/flux_csv_parser.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,12 @@ def _close(self):
8585

8686
def __enter__(self):
8787
"""Initialize CSV reader."""
88-
self._reader = csv_parser.reader(codecs.iterdecode(self._response, _UTF_8_encoding))
88+
# response can be exhausted by logger, so we have to use data that has already been read
89+
if hasattr(self._response, 'closed') and self._response.closed:
90+
from io import StringIO
91+
self._reader = csv_parser.reader(StringIO(self._response.data.decode(_UTF_8_encoding)))
92+
else:
93+
self._reader = csv_parser.reader(codecs.iterdecode(self._response, _UTF_8_encoding))
8994
return self
9095

9196
def __exit__(self, exc_type, exc_val, exc_tb):

influxdb_client/client/util/date_utils.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
"""Utils to get right Date parsing function."""
22
import datetime
3+
import threading
34
from datetime import timezone as tz
45

56
from dateutil import parser
67

78
date_helper = None
89

10+
lock_ = threading.Lock()
11+
912

1013
class DateHelper:
1114
"""
@@ -79,11 +82,15 @@ def get_date_helper() -> DateHelper:
7982
"""
8083
global date_helper
8184
if date_helper is None:
82-
date_helper = DateHelper()
83-
try:
84-
import ciso8601
85-
date_helper.parse_date = ciso8601.parse_datetime
86-
except ModuleNotFoundError:
87-
date_helper.parse_date = parser.parse
85+
with lock_:
86+
# avoid duplicate initialization
87+
if date_helper is None:
88+
_date_helper = DateHelper()
89+
try:
90+
import ciso8601
91+
_date_helper.parse_date = ciso8601.parse_datetime
92+
except ModuleNotFoundError:
93+
_date_helper.parse_date = parser.parse
94+
date_helper = _date_helper
8895

8996
return date_helper

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
'aioresponses>=0.7.3',
2727
'sphinx==1.8.5',
2828
'sphinx_rtd_theme',
29-
'jinja2==3.0.3'
29+
'jinja2==3.1.2'
3030
]
3131

3232
extra_requires = [

tests/test_InfluxDBClient.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import codecs
12
import http.server
23
import json
34
import logging
@@ -234,6 +235,19 @@ def test_username_password_authorization(self):
234235
self.client = InfluxDBClient(url=self.host, username="my-user", password="my-password", debug=True)
235236
self.client.query_api().query("buckets()", "my-org")
236237

238+
def test_query_and_debug(self):
239+
self.client.close()
240+
self.client = InfluxDBClient(url=self.host, token="my-token", debug=True)
241+
# Query
242+
results = self.client.query_api().query("buckets()", "my-org")
243+
self.assertIn("my-bucket", list(map(lambda record: record["name"], results[0].records)))
244+
# Query RAW
245+
results = self.client.query_api().query_raw("buckets()", "my-org")
246+
self.assertIn("my-bucket", codecs.decode(results.data))
247+
# Bucket API
248+
results = self.client.buckets_api().find_buckets()
249+
self.assertIn("my-bucket", list(map(lambda bucket: bucket.name, results.buckets)))
250+
237251
def _start_proxy_server(self):
238252
import http.server
239253
import urllib.request

tests/test_InfluxDBClientAsync.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import pytest
99
from aioresponses import aioresponses
1010

11-
from influxdb_client import Point, WritePrecision
11+
from influxdb_client import Point, WritePrecision, BucketsService
1212
from influxdb_client.client.exceptions import InfluxDBError
1313
from influxdb_client.client.influxdb_client_async import InfluxDBClientAsync
1414
from influxdb_client.client.warnings import MissingPivotFunction
@@ -297,6 +297,21 @@ async def test_redacted_auth_header(self):
297297

298298
self.assertIn("Authorization: ***", log_stream.getvalue())
299299

300+
@async_test
301+
async def test_query_and_debug(self):
302+
await self.client.close()
303+
self.client = InfluxDBClientAsync(url="http://localhost:8086", token="my-token", debug=True)
304+
# Query
305+
results = await self.client.query_api().query("buckets()", "my-org")
306+
self.assertIn("my-bucket", list(map(lambda record: record["name"], results[0].records)))
307+
# Query RAW
308+
results = await self.client.query_api().query_raw("buckets()", "my-org")
309+
self.assertIn("my-bucket", results)
310+
# Bucket API
311+
buckets_service = BucketsService(api_client=self.client.api_client)
312+
results = await buckets_service.get_buckets()
313+
self.assertIn("my-bucket", list(map(lambda bucket: bucket.name, results.buckets)))
314+
300315
async def _prepare_data(self, measurement: str):
301316
_point1 = Point(measurement).tag("location", "Prague").field("temperature", 25.3)
302317
_point2 = Point(measurement).tag("location", "New York").field("temperature", 24.3)

0 commit comments

Comments
 (0)