LargeBinary binds or raises depending on whether the value happens to be valid UTF-8
評価
調査の方向性
まず、方言のパラメーターまたはリテラルのレンダリングのエントリーポイントと、既存の LargeBinary の処理を見つけます。無効な UTF-8 の例を再現してから、bytes に対して提案されている hex/unhex 表現を実装します。UTF-8 の妥当性に依存せず、b'\x00\xff' を含むバイナリ値を同一の内容で挿入し、ラウンドトリップできれば完了です。
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- Python
- スター
- 15
- フォーク
- 5
- 平均マージ
- 1日 15時間
- マージ済み PR(30日)
- 1
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
databendlabs/databend-sqlalchemy のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
Index.create() reports success and creates nothing: the compiler emits an empty string and the connector returns early対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
do_rollback() swallows the connector's NotSupportedError, so a rollback reports success over a write that stands対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
Time is rendered as DATETIME, so a time-of-day is silently stored as a 1970-01-01 timestamp対応中かも @dwaddle が 7 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 58/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
databendlabs/databend-sqlalchemy#58 · コメント 1 件 ·
databendlabs/databend-sqlalchemy の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
ComposioHQ/awesome-claude-skills#2398 ·
メンテナーはふだん 2 日以内に返信
-
bug converter
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
grafana/sigma-rule-deployment#435 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 73/100
datamodel-code-generator/datamodel-code-generator#5589 ·
メンテナーはふだん 1 日以内に返信
-
Shell: serve the home app's Cookie Policy on a hard reload対応中かも @2001anshkaushik が今日担当しました。 オープンfeature module:ai
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
rocketride-org/rocketride-server#2899 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
GEFSv12
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100