Skip to content

Commit 1833b14

Browse files
committed
fix: = is valid sign for measurement name
1 parent 6d0312a commit 1833b14

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
1. [#112](https://github.com/influxdata/influxdb-client-python/pull/113): Support timestamp with different timezone in _convert_timestamp
55

66
### Bug Fixes
7-
1. [#115](https://github.com/influxdata/influxdb-client-python/pull/115): Fixed serialization of `\n`, `\r` and `\t` to Line Protocol
87
1. [#117](https://github.com/influxdata/influxdb-client-python/pull/117): Fixed appending default tags for single Point
8+
1. [#115](https://github.com/influxdata/influxdb-client-python/pull/115): Fixed serialization of `\n`, `\r` and `\t` to Line Protocol, `=` is valid sign for measurement name
99

1010
## 1.8.0 [2020-06-19]
1111

influxdb_client/client/write/point.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
EPOCH = UTC.localize(datetime.utcfromtimestamp(0))
1414
DEFAULT_WRITE_PRECISION = WritePrecision.NS
15+
_ESCAPE_MEASUREMENT = str.maketrans({'\\': '\\\\', ',': r'\,', ' ': r'\ ', '\n': '\\n', '\t': '\\t', '\r': '\\r'})
1516
_ESCAPE_KEY = str.maketrans({'\\': '\\\\', ',': r'\,', ' ': r'\ ', '=': r'\=', '\n': '\\n', '\t': '\\t', '\r': '\\r'})
1617
_ESCAPE_STRING = str.maketrans({'\"': r"\"", "\\": r"\\"})
1718

@@ -75,7 +76,7 @@ def field(self, field, value):
7576
return self
7677

7778
def to_line_protocol(self):
78-
_measurement = _escape_key(self._name)
79+
_measurement = _escape_key(self._name, _ESCAPE_MEASUREMENT)
7980
_tags = _append_tags(self._tags)
8081
_fields = _append_fields(self._fields)
8182
if not _fields:
@@ -133,8 +134,10 @@ def _append_time(time, write_precision):
133134
return f" {int(_convert_timestamp(time, write_precision))}"
134135

135136

136-
def _escape_key(tag):
137-
return str(tag).translate(_ESCAPE_KEY)
137+
def _escape_key(tag, escape_list=None):
138+
if escape_list is None:
139+
escape_list = _ESCAPE_KEY
140+
return str(tag).translate(escape_list)
138141

139142

140143
def _escape_tag_value(value):

tests/test_point.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ def test_TagEscapingKeyAndValue(self):
4646

4747
self.assertEqual("h\\n2\\ro\\t_data,carriage\\rreturn=carriage\\nreturn,new\\nline=new\\nline,t\\tab=t\\tab level=2i", point.to_line_protocol())
4848

49+
def test_EqualSignEscaping(self):
50+
51+
point = Point.measurement("h=2o") \
52+
.tag("l=ocation", "e=urope") \
53+
.field("l=evel", 2)
54+
55+
self.assertEqual("h=2o,l\\=ocation=e\\=urope l\\=evel=2i", point.to_line_protocol())
56+
4957
def test_OverrideTagField(self):
5058
point = Point.measurement("h2o") \
5159
.tag("location", "europe") \

0 commit comments

Comments
 (0)