Skip to content

Commit 5cbc212

Browse files
authored
fix: write a dictionary-style object without tags (influxdata#235)
1 parent 5f3ce1f commit 5cbc212

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
1. [#222](https://github.com/influxdata/influxdb-client-python/pull/222): Pass configured timeout to HTTP client
88
1. [#218](https://github.com/influxdata/influxdb-client-python/pull/218): Support for `with .. as ..` statement
99
1. [#232](https://github.com/influxdata/influxdb-client-python/pull/232): Specify package requirements in `setup.py`
10+
1. [#235](https://github.com/influxdata/influxdb-client-python/pull/235): Write a dictionary-style object without tags
1011

1112
## 1.16.0 [2021-04-01]
1213

influxdb_client/client/write_api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ def _append_default_tag(self, key, val, record):
353353
elif isinstance(record, Point):
354354
record.tag(key, val)
355355
elif isinstance(record, dict):
356+
record.setdefault("tags", {})
356357
record.get("tags")[key] = val
357358
elif isinstance(record, Iterable):
358359
for item in record:

tests/test_WriteApi.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,19 @@ def test_writes_asynchronous_without_retry(self):
502502
self.assertEqual("Service Unavailable", exception.reason)
503503
self.assertEqual(1, len(httpretty.httpretty.latest_requests))
504504

505+
def test_writes_default_tags_dict_without_tag(self):
506+
httpretty.register_uri(httpretty.POST, uri="http://localhost/api/v2/write", status=204)
507+
508+
point_settings = PointSettings(**{"id": "132-987-655", "customer": "California Miner"})
509+
self.write_client = self.influxdb_client.write_api(write_options=SYNCHRONOUS,
510+
point_settings=point_settings)
511+
512+
self.write_client.write("my-bucket", "my-org", {"measurement": "h2o", "fields": {"level": 1.0}, "time": 1})
513+
514+
requests = httpretty.httpretty.latest_requests
515+
self.assertEqual(1, len(requests))
516+
self.assertEqual("h2o,customer=California\\ Miner,id=132-987-655 level=1 1", requests[0].parsed_body)
517+
505518

506519
class AsynchronousWriteTest(BaseTest):
507520

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy