Skip to content

[Bug]: Python SELECT convenience builder ignores explicit limit=0 #30824

Closed

Description

@MatrixAdventurer

由 LW 授权的 ChatGPT Personal 智能体提交。

Is there an existing issue for the same bug?

  • Searched open and closed issues/PRs for build_select_query, zero limit and Python limit=0. Server-side prepared/recursive LIMIT fixes concern different owners; no matching SDK convenience-function fix was found.

Branch Name

main (no exact upstream dev exists; main fallback is explicitly authorized).

Commit ID

6cbe375

Other Environment Information

Python 3.12.14, SQLAlchemy 1.4.54; deterministic native SQLite DBAPI execution of SQL generated by the actual public SDK builder. No production service/data was accessed.

Actual Behavior

build_select_query(table_name="t", limit=0) omits LIMIT entirely because its convenience wrapper tests truthiness. The underlying MatrixOneSQLBuilder.limit(0).build() correctly keeps LIMIT 0. A caller requesting no rows therefore receives an unrestricted query, potentially fetching the entire matching dataset.

Expected Behavior

Only None omits the LIMIT clause. Explicit zero must generate LIMIT 0, returning an empty result. Positive limits and both parameter-substitution/binding modes must keep their existing behavior.

Steps to Reproduce

Create a disposable SQLite table with IDs 1,2,3. Build a SELECT of id with WHERE id >= ? (parameter 2), ORDER BY id and limit=0; execute the generated SQL through native DBAPI in each parameter mode. Actual result is [(2,), (3,)], expected [].
The committed-candidate regression covers None/0/1/5 in both modes. Against original production: 2 failed / 6 passed; fixed owning file: 38 passed. Full SDK offline: 1268 passed +86 subtests. Independent reviewer reproduced both original failures and fixed results and explicitly Approved the complete two-file delta.

Additional information

Candidate scope: 2 files, +26/-1. The one-line guard restores the existing builder contract; no server, dependency, schema, API signature or generated source change. This is SQL generation validation, not live MatrixOne or full hosted CI certification. Packaging/hosted checks are recorded separately when complete.
Authenticated subject MatrixAdventurer and its own fork MatrixAdventurer/matrixone (parent matrixorigin/matrixone, push permission) were freshly verified. Planned fork feature branch: fix/python-select-zero-limit-20261022. Branch/commit/PR operations and read-only verification are by the signed execution subject; no upstream/default branch push, automatic merge, deployment or issue closure.

由 LW 授权的 ChatGPT Personal 智能体提交。

Activity

  1. Ariznawlll commented on Oct 22, 2026

    @Ariznawlll
    Collaborator

    测试版本

    • 分支:main;日期:2026-10-22。
    • 实际 SDK 完整 SHA:3ad9adbb4ce6c9f8e421917233cc6f6d40ab5f25。测试前及结束核对官方 main 相同;隔离 checkout 无源码修改,并验证实际导入 sql_builder.py 来自该 checkout。
    • 已阅读修复及审阅说明;PR fix(python-sdk): preserve explicit zero SELECT limits #30825 已 MERGED,merge commit b90e839af241184d14ac819ddc894e9dee097262 已验证在上述 main 祖先链。不是对未合入候选进行验收。
    • macOS arm64,本机原生 SQLite 内存 DBAPI;Python 3.12.3 / SQLAlchemy 2.1.6 与 Python 3.11.4 / SQLAlchemy 2.0.45。此 issue 是纯 SDK SQL 生成缺陷,按原报告的 SQLite 执行方式验证,无 MO 服务二进制、共享集群或真实业务数据参与。不宣称在线服务或原报告精确依赖版本复测通过。

    原问题验证

    使用实际公开 API build_select_query,建三行 id=1/2/3,WHERE id >= ? 绑定2,ORDER BY id,在参数替换及保留绑定两种模式下执行生成 SQL。limit=None 返回2/3,limit=0 明确生成 LIMIT 0 且返回空集,limit=1 返回2,limit=2/5 返回2/3。

    扩展矩阵在两个解释器上各3/3通过;正常 MOTR runner 另重复3次,最终 total=3 / success=3 / failed=0 / skipped=0,2.12s。不是仅检查生成字符串。

    读取修复提交父版本的真实 sql_builder.py(不改工作树)执行同一 oracle,被拒绝;两个旧 zero-limit 模式均遗漏 LIMIT,而旧底层 MatrixOneSQLBuilder.limit(0) 控制保留 LIMIT 0。该对照明确区分修复前缺陷与本次修复结果,不作为修复失败。

    Happy Path 覆盖

    1. None/0/1/2/5 两种模式的确切有序结果;重复0/None调用,避免前次 limit 状态串扰。
    2. 无过滤 limit=0 仍为空;无匹配行的普通查询为空。
    3. 两列结果逐值校验,id 为 int,label 为 str 或 None;NULL 行为 (2,None),非 ASCII 字符串为 (3,'中文'),两种模式一致。
    4. 正数边界不截错行、不额外返回行;所有 SELECT 后原三行数据完整。

    Unhappy Path 覆盖

    1. 不存在的投影列由 SQLite DBAPI 拒绝,必须为 no such column;失败后全表三行两列与原始独立常量逐项一致,随后的正常 limit=0 仍为空。这里验证客户端生成/调用隔离,不把 SQLite 错误号当 MO 错误号。
    2. 每轮 DROP TABLE 后检查 sqlite_master 无残留对象,finally 关闭连接。没有共享数据库清理或持久化文件。
    3. 缺少 SDK 测试 opt-in 返回77,明确 skip 而非 pass;启用后缺少依赖会失败。早期全量 offline 的8项 localhost监听被沙箱权限阻断,允许隔离回环 fixture 后原样重跑通过;初次 runner 缺 PyYAML 在测试前失败,换用已配置解释器后通过。两者不归类为产品失败。

    白盒验证

    读取一行 None 判断修复及已有执行型回归。已有 owning file clients/python/tests/offline/test_vector_operations.py 每轮38项,连续3轮全通过。最新 main 的整个 SDK offline suite 实跑 1272 passed、86 subtests passed,2条既有 deprecation warning,2.76s;未以研发此前的1268计数代替本次执行。

    Go/race 不适用:本项是顺序执行、无后台任务或共享状态的 Python SQL 生成路径,没有服务器代码变更。没有新增 MO PR。

    回归测试

    新增独立 MOTR PR #260,head 859586ea4a0caa3ec7d37ae55b330fbce7bab82d,基于官方 MOTR main 13a6aad987e93be1883daa54f08a63d4cc5fe5a2,未追加 #247。当前 OPEN/draft,未声称已合入。

    固定版本 SDK 场景 包含确定性 out 与配置文档;4项新增 oracle 测试拒绝旧版遗漏 LIMIT 0 和错误正数截断。MOTR 全量离线框架 432项通过,28.908s;这不是432项在线产品验收。完整14_issue_regression产品suite、在线MO/集成suite未执行。

    独立查询 修复 PR CI 39750941783 的 job/step:6个 Python/SQLAlchemy offline job及CI Required成功,online跳过。该CI属于候选head e46e614dd1ac84c0aa0384395c434b7dc1aaa9e5,不是最新main或新MOTR分支CI。本次 MOTR CI 39799016339 检查时 queued,尚无通过结论;未手动触发昂贵CI。

    测试证据

    本地目录 /tmp/mo-sdk-30824-4VhA8o/:verify.log、sdk-owning-3.log、sdk-offline.log、motr-final.log、motr-offline.log,及上述固定版本回归代码。日志未冒充已上传artifact。结论仅覆盖上述 main SDK 原问题及列明边界,不代表4.2发布线、在线MO或完整集成CI。

    测试结论

    测试通过。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugneeds-triage

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions