influxdata / influxdata/influxdb-client-python

Empty string in database becomes None value in Python

Offen
#570 0 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

bug
Vorherrschende Sprache
Python
Sterne
793
Forks
186
Ø Merge
3 Std. 2 Min.
Gemergte PRs (30 T.)
1

Beschreibung

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

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, die Python-Reproduktion mit der gezeigten Flux-Abfrage auszuführen, und vergleiche die erwarteten und tatsächlichen _value-Werte. Verfolge, wie query_api().query(q) den zurückgegebenen Datensatz analysiert, und überprüfe anschließend, dass eine leere Zeichenfolge im Ergebnis als "" und nicht als None erhalten bleibt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
database
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
42/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.