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 分钟
- 30 天内合并 PR
- 37
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 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 一周以上 新手友好度 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-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 天内回复