Skip to content

Empty string in database becomes None value in Python #570

Open
@hy144328

Description

@hy144328

Specifications

  • Client Version: 1.34.0
  • InfluxDB Version: 2.6.1
  • Platform: Linux

Code sample to reproduce problem

import influxdb_client

with influxdb_client.InfluxDBClient(
    org = ...,
    token = ...,
    url = ...,
) as client:
    q = f"""
        from(bucket: ...)
        //|> filter(fn: (r) => exists r._value)
        //|> filter(fn: (r) => r._value != "")
        |> last()
    """
    res = [
        record_it.values
        for table_it in client.query_api().query(q)
        for record_it in table_it.records
    ]
    print(res)

Expected behavior

[{'result': '_result', 'table': 0, '_time': datetime.datetime(2023, 3, 2, 18, 47, 7, 547036, tzinfo=tzutc()), '_value': ''}]

Actual behavior

[{'result': '_result', 'table': 0, '_time': datetime.datetime(2023, 3, 2, 18, 47, 7, 547036, tzinfo=tzutc()), '_value': None}]

Additional info

last() function:

If [_value] column is null in the last record, last() returns the previous record with a non-null value.

My last record with a non-null _value has the empty string for _value.
So far, the row is correctly identified.
But by the time I read _value from the result returned in Python, the record does not hold the empty string "" but None.

I verified that the value of _value is really the empty string in the database and not None by experimenting with filters (see commented code).
I find it more intuitive to leave the empty string as empty string in Python.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions