builder: order_by("col", "asc") silently treats the direction as a column
メンテナーはふだん 1 日以内に返信
評価
この issue はまだ評価されていません。
説明
Summary
order_by("column", "asc") and order_by("column", "desc") build without error and treat the direction word as a second column. The mistake only surfaces when the database rejects the query, and with "desc" the caller's intended sort direction is dropped.
Reproduction
sqlspec==0.74.2
from sqlspec import sql
sql.select("u.id").from_("users u").order_by("u.name", "asc").build(dialect="postgres").sql
sql.select("u.id").from_("users u").order_by("u.name", "desc").build(dialect="postgres").sql
Output:
SELECT "u"."id" AS "id" FROM "users" AS "u" ORDER BY "u"."name", "u"."asc"
SELECT "u"."id" AS "id" FROM "users" AS "u" ORDER BY "u"."name", "u"."desc"
PostgreSQL then fails with an undefined-column error for u.asc / u.desc. If the query has a single unqualified table that happens to have such a column, it would run and sort by the wrong thing.
The supported forms work as expected:
order_by("u.name", desc=True) # ORDER BY "u"."name" DESC
order_by("u.name DESC") # ORDER BY "u"."name" DESC
Why it happens
The signature is order_by(*items, desc=False), so every positional string is an order item. (column, direction) is a common calling convention in other query APIs, which makes this an easy slip, and nothing in the builder flags it.
Proposed change
Either of these would catch it at build time:
- Raise
SQLBuilderErrorwhen a positional item is exactlyascordesc(case-insensitive), with a message pointing todesc=Trueor"col DESC". - Accept a trailing
"asc"/"desc"as the direction for the preceding item.
Option 1 is the smaller change and adds no new calling convention. A column that is really named asc or desc can still be passed quoted or as a column expression.
- 主要言語
- Python
- スター
- 110
- フォーク
- 11
- 平均マージ
- 19時間 9分
- マージ済み PR(30日)
- 37
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
litestar-org/sqlspec のほかの issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
litestar-org/sqlspec#946 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
litestar-org/sqlspec#945 ·
メンテナーはふだん 1 日以内に返信
-
builder: explain why boolean projections are rejected in sql.select() string columns対応中かも @cofin が 1 日前に担当しました。 オープンenhancement
litestar-org/sqlspec#943 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
feat(litestar): support Litestar v3 compatibility and DI changes対応中かも @cofin が 14 日前に担当しました。 オープンenhancement
litestar-org/sqlspec#926 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 20/100
litestar-org/sqlspec#509 ·
メンテナーはふだん 1 日以内に返信
litestar-org/sqlspec の issue をすべて見る
似ている issue
-
area:cli area:docs Platform vdr
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
NVIDIA-NeMo/Gym#7192 ·
メンテナーはふだん 2 日以内に返信
-
Bug: CaseInsensitiveDict (event.headers) returns True for both == and != against the same mappingオープンbug triage
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
aws-powertools/powertools-lambda-python#8948 ·
メンテナーはふだん 1 日以内に返信
-
SofyaBotオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
ai-robots-txt/ai.robots.txt#324 ·
-
[Resource]: Dashbarオープンresource-submission validation-passed
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
hesreallyhim/awesome-claude-code#3821 · コメント 1 件 ·
-
bug good first issue help wanted level 1 wocs
難易度 2/5 1〜3時間 初心者へのやさしさ 92/100
GianlucaBave/murmury#169 ·
メンテナーはふだん 1 日以内に返信