builder: order_by("col", "asc") silently treats the direction as a column
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
Issue này chưa được đánh giá.
Mô tả
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.
- Ngôn ngữ chính
- Python
- Star
- 110
- Fork
- 11
- Merge trung bình
- 19 giờ 9 phút
- Pull request đã merge (30 ngày)
- 37
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của litestar-org/sqlspec
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
litestar-org/sqlspec#946 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
litestar-org/sqlspec#945 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
builder: explain why boolean projections are rejected in sql.select() string columnsCó thể đã có người làm @cofin đã nhận 1 ngày trước. Đang mởenhancement
litestar-org/sqlspec#943 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
feat(litestar): support Litestar v3 compatibility and DI changesCó thể đã có người làm @cofin đã nhận 14 ngày trước. Đang mởenhancement
litestar-org/sqlspec#926 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 20/100
litestar-org/sqlspec#509 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của litestar-org/sqlspec
Issue tương tự
-
area:cli area:docs Platform vdr
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
NVIDIA-NeMo/Gym#7192 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Bug: CaseInsensitiveDict (event.headers) returns True for both == and != against the same mappingĐang mởbug triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
aws-powertools/powertools-lambda-python#8948 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
SofyaBotĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
ai-robots-txt/ai.robots.txt#324 ·
-
[Resource]: DashbarĐang mởresource-submission validation-passed
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 78/100
hesreallyhim/awesome-claude-code#3821 · 1 bình luận ·
-
bug good first issue help wanted level 1 wocs
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 92/100
GianlucaBave/murmury#169 ·
Maintainer thường phản hồi trong vòng 1 ngày