Skip to content

Commit

Permalink
Fix make_lines excludes fields with empty strings (influxdata#655) (i…
Browse files Browse the repository at this point in the history
…nfluxdata#766)

* Fix make_lines excludes fields with empty strings (influxdata#655)

Converting to unicode required something to be done with None values. They were
converted to empty strings which were subsequently ignored. This makes it
impossible to write an explicitly empty string, which should be possible. This
change distinguishes between None and empty strings.

* Fix linting failure due to long comment line

Co-authored-by: Greg Schrock <[email protected]>
  • Loading branch information
gregschrock and gregschrock authored Apr 10, 2020
1 parent e884631 commit 7d82f93
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
6 changes: 4 additions & 2 deletions influxdb/line_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,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)

if isinstance(value, integer_types) and not isinstance(value, bool):
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 @@ -117,6 +117,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

0 comments on commit 7d82f93

Please sign in to comment.