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

make_lines omits field values with empty strings #655

Closed
rhestilow-skytap opened this issue Oct 31, 2018 · 1 comment
Closed

make_lines omits field values with empty strings #655

rhestilow-skytap opened this issue Oct 31, 2018 · 1 comment

Comments

@rhestilow-skytap
Copy link

When writing a point where one or more field values are empty strings (""), influxdb-python will omit them in the line protocol representation. If there are no non-empty fields, this will omit all fields, resulting in an invalid line protocol format and an error.

For example, the following is allowed on the influx command line interface:

> INSERT m0 value=""
> SELECT * FROM m0
name: m0
time                value
----                -----
1540946138927548393

However, the equivalent in python results in an InfluxDBClientError:

def test_client_nonempty_field_string(client):
    point = {
            "measurement": "m0",
            "fields": { "value": "foo" },
    }

    # succeeds
    client.write_points([point])

def test_client_empty_field_string(client):
    point = {
            "measurement": "m0",
            "fields": { "value": "" },
    }

    # raises InfluxDBClientError: 400: {"error":"unable to parse 'm0 ': invalid field format"}
    client.write_points([point])

This appears to be related to the None handling introduced in commit 26683a4. In that commit, a conversion from None to '' was introduced in _get_unicode, and subsequently field values == '' are filtered out in make_lines. However, if a user explicitly passes in '' for a field value, then those values will get caught in this check and be filtered out as well.

This affects version 5.2.0 and earlier, and was tested against influxdb 1.4.3. It may also be related to #549.

sebito91 pushed a commit that referenced this issue Apr 10, 2020
* 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.

* Fix linting failure due to long comment line

Co-authored-by: Greg Schrock <gschrock@128technology.com>
@sebito91
Copy link
Contributor

Closed by #766

ocworld pushed a commit to AhnLab-OSS/influxdb-python that referenced this issue Apr 13, 2020
…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 <gschrock@128technology.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants