Skip to content

Commit

Permalink
fix: write a dictionary-style object without tags (#235)
Browse files Browse the repository at this point in the history
  • Loading branch information
bednar authored Apr 27, 2021
1 parent 5f3ce1f commit 5cbc212
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
1 change: 1 addition & 0 deletions influxdb_client/client/write_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 13 additions & 0 deletions tests/test_WriteApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down

0 comments on commit 5cbc212

Please sign in to comment.