Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty string in database becomes None value in Python #570

Open
hy144328 opened this issue Mar 31, 2023 · 0 comments
Open

Empty string in database becomes None value in Python #570

hy144328 opened this issue Mar 31, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@hy144328
Copy link

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.

@hy144328 hy144328 added the bug Something isn't working label Mar 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant