From a3cd15604d6dfe6a27a7ce56871d3ae79b21e42c Mon Sep 17 00:00:00 2001 From: Greg Schrock Date: Mon, 11 Nov 2019 12:26:15 -0500 Subject: [PATCH 1/2] Fix make_lines excludes fields with empty strings (#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. --- influxdb/line_protocol.py | 6 ++++-- influxdb/tests/test_line_protocol.py | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/influxdb/line_protocol.py b/influxdb/line_protocol.py index 249511d3..ac2dcd8f 100644 --- a/influxdb/line_protocol.py +++ b/influxdb/line_protocol.py @@ -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' diff --git a/influxdb/tests/test_line_protocol.py b/influxdb/tests/test_line_protocol.py index bccd7727..d96f46fd 100644 --- a/influxdb/tests/test_line_protocol.py +++ b/influxdb/tests/test_line_protocol.py @@ -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 in TestLineProtocol object.""" + 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 = { From bfa5c5e536f7f361c426c9f5ae6436855cc211b3 Mon Sep 17 00:00:00 2001 From: Greg Schrock Date: Mon, 11 Nov 2019 14:33:10 -0500 Subject: [PATCH 2/2] Fix linting failure due to long comment line --- influxdb/tests/test_line_protocol.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/influxdb/tests/test_line_protocol.py b/influxdb/tests/test_line_protocol.py index d96f46fd..8e7591b5 100644 --- a/influxdb/tests/test_line_protocol.py +++ b/influxdb/tests/test_line_protocol.py @@ -116,7 +116,7 @@ def test_make_lines_unicode(self): ) def test_make_lines_empty_field_string(self): - """Test make lines with an empty string field in TestLineProtocol object.""" + """Test make lines with an empty string field.""" data = { "points": [ {