LargeBinary binds or raises depending on whether the value happens to be valid UTF-8
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 68/100
Direzione di ricerca
Inizia individuando il punto di ingresso per la rappresentazione dei parametri o dei literal del dialetto e la gestione esistente di LargeBinary. Riproduci gli esempi di UTF-8 non valido, quindi implementa la rappresentazione hex/unhex suggerita per i bytes. Il lavoro è completato quando i valori binari, incluso b'\x00\xff', vengono inseriti e recuperati identici senza dipendere dalla validità di UTF-8.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Versions
- databend-sqlalchemy 0.5.5
- databend-driver 0.34.2
- SQLAlchemy 2.0.51
- Python 3.12.9, macOS
- Server:
datafuselabs/databend:v1.2.925-patch-4in Docker
What happens
The dialect renders parameters into the statement text, so a bytes value gets decoded as UTF-8 on the way in. Whether a LargeBinary insert works therefore depends on the value, not the type. One value at a time, everything else held constant:
| value | valid UTF-8 | result |
|---|---|---|
b'\x00\x01' |
yes | binds, round-trips identically |
b'abc' |
yes | binds, round-trips identically |
b'\xc3\xa9' |
yes | binds, round-trips identically |
b'\x00\xff' |
no | 'utf-8' codec can't decode byte 0xff in position 1 |
b'\xff' |
no | same |
b'\x80' |
no | same |
The database is not the problem. A BINARY column given unhex('00ff') reads back as b'\x00\xff' without complaint.
Why this one bothered me
Valid UTF-8 isn't a property binary data has. So the column works right up until the day the bytes have a high one in them — and a test suite with ASCII-ish fixtures will never see it. That's worse than a flat refusal, because a refusal gets found on day one. I ended up declaring LargeBinary unstorable on this dialect rather than let it fail per value, which loses a column type the database supports perfectly well.
Suggested fix
Hex-encode bytes parameters and emit unhex('…') — the server already accepts that, as above.
Some background, in case it's useful: databendlabs/bendsql#583 asked for real parameter binding in the driver, and interpolating into statement text is what makes bytes unrepresentable here. For what it's worth, trino-python-client gets this wrong from the identical cause — its literal formatter calls .encode() on the value, which is what you'd do to a str. Interpolating parameters into SQL seems to be what gets bytes wrong, whoever does it.
- Lingua principale
- Python
- Stelle
- 15
- Fork
- 5
- Merge medio
- 1g 15h
- PR unite (30g)
- 1
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di databendlabs/databend-sqlalchemy
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
Index.create() reports success and creates nothing: the compiler emits an empty string and the connector returns earlyForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
do_rollback() swallows the connector's NotSupportedError, so a rollback reports success over a write that standsForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
Time is rendered as DATETIME, so a time-of-day is silently stored as a 1970-01-01 timestampForse già presa @dwaddle l’ha presa 4 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 58/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
databendlabs/databend-sqlalchemy#58 · 1 commento ·
Tutte le issue di databendlabs/databend-sqlalchemy
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
nansencenter/geodataset#39 ·
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
awslabs/visual-asset-management-system#804 ·
I maintainer di solito rispondono entro 1 giorno
-
follow-up
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
odoo/odoo#297927 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
link-rot
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 67/100