influxdata / influxdata/influxdb-client-python

Empty string in database becomes None value in Python

Open
#570 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
793
Forks
186
Avg merge
3h 2m
Merged PRs (30d)
1

Description

### Specifications

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

### Code sample to reproduce problem

```python
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](https://docs.influxdata.com/flux/v0.x/stdlib/universe/last/):

> 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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the Python reproduction with the shown Flux query and compare the expected and actual _value values. Trace how query_api().query(q) parses the returned record, then verify that an empty string remains "" rather than becoming None in the result.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.