Skip to content

Commit 7d82f93

Browse files
authored
Fix make_lines excludes fields with empty strings (influxdata#655) (influxdata#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 <gschrock@128technology.com>
1 parent e884631 commit 7d82f93

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

influxdb/line_protocol.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,11 @@ def _is_float(value):
104104

105105

106106
def _escape_value(value):
107-
value = _get_unicode(value)
107+
if value is None:
108+
return ''
108109

109-
if isinstance(value, text_type) and value != '':
110+
value = _get_unicode(value)
111+
if isinstance(value, text_type):
110112
return quote_ident(value)
111113

112114
if isinstance(value, integer_types) and not isinstance(value, bool):

influxdb/tests/test_line_protocol.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,24 @@ def test_make_lines_unicode(self):
117117
'test,unicode_tag=\'Привет!\' unicode_val="Привет!"\n'
118118
)
119119

120+
def test_make_lines_empty_field_string(self):
121+
"""Test make lines with an empty string field."""
122+
data = {
123+
"points": [
124+
{
125+
"measurement": "test",
126+
"fields": {
127+
"string": "",
128+
}
129+
}
130+
]
131+
}
132+
133+
self.assertEqual(
134+
line_protocol.make_lines(data),
135+
'test string=""\n'
136+
)
137+
120138
def test_tag_value_newline(self):
121139
"""Test make lines with tag value contains newline."""
122140
data = {

0 commit comments

Comments
 (0)