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

Fix make_lines excludes fields with empty strings (#655) #766

Merged
merged 2 commits into from
Apr 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions influxdb/line_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,11 @@ def _is_float(value):


def _escape_value(value):
value = _get_unicode(value)
if value is None:
return ''

if isinstance(value, text_type) and value != '':
value = _get_unicode(value)
if isinstance(value, text_type):
return quote_ident(value)
elif isinstance(value, integer_types) and not isinstance(value, bool):
return str(value) + 'i'
Expand Down
18 changes: 18 additions & 0 deletions influxdb/tests/test_line_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,24 @@ def test_make_lines_unicode(self):
'test,unicode_tag=\'Привет!\' unicode_val="Привет!"\n'
)

def test_make_lines_empty_field_string(self):
"""Test make lines with an empty string field."""
data = {
"points": [
{
"measurement": "test",
"fields": {
"string": "",
}
}
]
}

self.assertEqual(
line_protocol.make_lines(data),
'test string=""\n'
)

def test_tag_value_newline(self):
"""Test make lines with tag value contains newline."""
data = {
Expand Down