Skip to content

Commit 28dee66

Browse files
author
aviau
committed
Dont include empty tags in lines (Closes: influxdata#215)
1 parent 815f7f9 commit 28dee66

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

influxdb/line_protocol.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ def make_lines(data):
7979
tags.update(point.get('tags', {}))
8080
# tags should be sorted client-side to take load off server
8181
for tag_key in sorted(tags.keys()):
82-
lines += "{key}={value},".format(
83-
key=_escape_tag(tag_key),
84-
value=_escape_tag(tags[tag_key]),
85-
)
82+
key = _escape_tag(tag_key)
83+
value = _escape_tag(tags[tag_key])
84+
if key != '' and value != '':
85+
lines += "{key}={value},".format(key=key, value=value)
8686
lines = lines[:-1] + " " # strip the trailing comma
8787

8888
# add fields

tests/influxdb/test_line_protocol.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import unittest
4+
from influxdb import line_protocol
5+
6+
7+
class TestLineProtocol(unittest.TestCase):
8+
9+
def test_empty_tag(self):
10+
data = {
11+
"tags": {
12+
"my_tag": ""
13+
},
14+
"points": [
15+
{
16+
"measurement": "test",
17+
"fields": {
18+
"value": "hello!"
19+
}
20+
}
21+
]
22+
}
23+
24+
self.assertEqual(
25+
line_protocol.make_lines(data),
26+
'test value="hello!"\n'
27+
)

0 commit comments

Comments
 (0)