From 5cbc21273e3d778bd7d4e427051e1a8d5c4aa655 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Bedn=C3=A1=C5=99?= Date: Tue, 27 Apr 2021 10:37:06 +0200 Subject: [PATCH] fix: write a dictionary-style object without tags (#235) --- CHANGELOG.md | 1 + influxdb_client/client/write_api.py | 1 + tests/test_WriteApi.py | 13 +++++++++++++ 3 files changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f5477a5d..f52c597e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ 1. [#222](https://github.com/influxdata/influxdb-client-python/pull/222): Pass configured timeout to HTTP client 1. [#218](https://github.com/influxdata/influxdb-client-python/pull/218): Support for `with .. as ..` statement 1. [#232](https://github.com/influxdata/influxdb-client-python/pull/232): Specify package requirements in `setup.py` +1. [#235](https://github.com/influxdata/influxdb-client-python/pull/235): Write a dictionary-style object without tags ## 1.16.0 [2021-04-01] diff --git a/influxdb_client/client/write_api.py b/influxdb_client/client/write_api.py index ca058dc0..aa8e238c 100644 --- a/influxdb_client/client/write_api.py +++ b/influxdb_client/client/write_api.py @@ -353,6 +353,7 @@ def _append_default_tag(self, key, val, record): elif isinstance(record, Point): record.tag(key, val) elif isinstance(record, dict): + record.setdefault("tags", {}) record.get("tags")[key] = val elif isinstance(record, Iterable): for item in record: diff --git a/tests/test_WriteApi.py b/tests/test_WriteApi.py index 1bb6f9a1..8480068d 100644 --- a/tests/test_WriteApi.py +++ b/tests/test_WriteApi.py @@ -502,6 +502,19 @@ def test_writes_asynchronous_without_retry(self): self.assertEqual("Service Unavailable", exception.reason) self.assertEqual(1, len(httpretty.httpretty.latest_requests)) + def test_writes_default_tags_dict_without_tag(self): + httpretty.register_uri(httpretty.POST, uri="http://localhost/api/v2/write", status=204) + + point_settings = PointSettings(**{"id": "132-987-655", "customer": "California Miner"}) + self.write_client = self.influxdb_client.write_api(write_options=SYNCHRONOUS, + point_settings=point_settings) + + self.write_client.write("my-bucket", "my-org", {"measurement": "h2o", "fields": {"level": 1.0}, "time": 1}) + + requests = httpretty.httpretty.latest_requests + self.assertEqual(1, len(requests)) + self.assertEqual("h2o,customer=California\\ Miner,id=132-987-655 level=1 1", requests[0].parsed_body) + class AsynchronousWriteTest(BaseTest):