Fix InfluxDB v2 API with write precision None (#41937)

This commit is contained in:
Rob Bierbooms 2020-10-16 16:44:50 +02:00 committed by GitHub
parent 1e256e6122
commit 92f89213a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 4 deletions

View file

@ -342,8 +342,13 @@ def get_influx_connection(conf, test_write=False, test_read=False):
def write_v2(json):
"""Write data to V2 influx."""
data = {"bucket": bucket, "record": json}
if precision is not None:
data["write_precision"] = precision
try:
write_api.write(bucket=bucket, record=json, write_precision=precision)
write_api.write(**data)
except (urllib3.exceptions.HTTPError, OSError) as exc:
raise ConnectionError(CONNECTION_ERROR % exc) from exc
except ApiException as exc:

View file

@ -61,10 +61,17 @@ def mock_client_fixture(request):
@pytest.fixture(name="get_mock_call")
def get_mock_call_fixture(request):
"""Get version specific lambda to make write API call mock."""
def v2_call(body, precision):
data = {"bucket": DEFAULT_BUCKET, "record": body}
if precision is not None:
data["write_precision"] = precision
return call(**data)
if request.param == influxdb.API_VERSION_2:
return lambda body, precision=None: call(
bucket=DEFAULT_BUCKET, record=body, write_precision=precision
)
return lambda body, precision=None: v2_call(body, precision)
# pylint: disable=unnecessary-lambda
return lambda body, precision=None: call(body, time_precision=precision)