Skip to content
This repository was archived by the owner on Oct 29, 2024. It is now read-only.

Commit dc83fc6

Browse files
syhanaviau
authored andcommitted
Fix newline in tag value cause partial commit (#716)
When a tag value contains newline(\n), the request sent to db would be splitted into two parts and the first part would fail to write to db but the second woudl be succeed. The reason is that before sending we do serialization (make_lines) the _escape_tag method in line_protocol.py won't handle it well, we need somehow more specific on newline instead of only handling escape character (\)
1 parent 47d24c7 commit dc83fc6

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

influxdb/line_protocol.py

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ def _escape_tag(tag):
5454
",", "\\,"
5555
).replace(
5656
"=", "\\="
57+
).replace(
58+
"\n", "\\n"
5759
)
5860

5961

influxdb/tests/test_line_protocol.py

+21
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,27 @@ def test_make_lines_unicode(self):
115115
'test,unicode_tag=\'Привет!\' unicode_val="Привет!"\n'
116116
)
117117

118+
def test_tag_value_newline(self):
119+
"""Test make lines with tag value contains newline."""
120+
data = {
121+
"tags": {
122+
"t1": "line1\nline2"
123+
},
124+
"points": [
125+
{
126+
"measurement": "test",
127+
"fields": {
128+
"val": "hello"
129+
}
130+
}
131+
]
132+
}
133+
134+
self.assertEqual(
135+
line_protocol.make_lines(data),
136+
'test,t1=line1\\nline2 val="hello"\n'
137+
)
138+
118139
def test_quote_ident(self):
119140
"""Test quote indentation in TestLineProtocol object."""
120141
self.assertEqual(

0 commit comments

Comments
 (0)