Skip to content

[Bug]: FulltextSearchBuilder.limit(0) is silently dropped #31403

Description

@Ariznawlll

DRAFT 24 (SDK, 2026-10-27) — filing now

Title: [Bug]: FulltextSearchBuilder.limit(0) is silently dropped (falsy check) and diverges from the ORM builder's correct is-not-None handling

Description

FulltextSearchBuilder._build_sql (sqlalchemy_ext/fulltext_search.py:~1600) renders:

limit_clause = f"LIMIT {self._limit_value}" if self._limit_value else ""
offset_clause = f"OFFSET {self._offset_value}" if self._offset_value else ""

Both use truthiness, not is not None — so limit(0) (a legitimate value, e.g. pagination dry-run, count-it-yourself, UI zero-page) is silently dropped and the query runs unbounded:

b = builder.limit(0)
print(b.explain())
# SELECT ... FROM t WHERE MATCH(...)   ← no LIMIT at all; limit(0) expected "LIMIT 0"

Verified min-repro of the exact conditional (pure python) plus the method itself (def limit(self, count): self._limit_value = count — stores 0, then build drops it).

Same builder, adjacent finding (recording in the same issue since the fix is the same function): the search mode used by this builder defaults to NATURAL_LANGUAGE while the ORM-facing FulltextFilter defaults to BOOLEAN for the same must()-style calls — two full-text front doors with different implicit semantics; plus _where_conditions are raw-joined strings (unescaped family, one more site for the unified escaping fix).

Reproduction

from matrixone.sqlalchemy_ext.fulltext_search import FulltextSearchBuilder
b = FulltextSearchBuilder(client).table("docs").columns("body").add_term("alpha").limit(0)
sql = b.explain()      # or _build_sql()
assert "LIMIT" not in sql   # ← passes; expected "LIMIT 0"

Impact

Expected behavior

Use is not None for both clauses (LIMIT/OFFSET), aligning with sql_builder.py's existing correct pattern; unify the default search mode across the two fulltext front doors (or document the difference loudly); include the raw _where_conditions join in the escaping-family fix. Regression: explain() for limit(0), limit(5), limit(None), offset(0) asserting exact clauses.

Activity

  1. added
    kind/bug
    on Oct 27, 2026
  2. added this to the MO-202610 milestone on Oct 27, 2026
  3. added theissue type on Oct 27, 2026
  4. added a commit that references this issue on Oct 30, 2026
    bbfe556
  5. XuPeng-SH commented on Oct 30, 2026

    @XuPeng-SH
    Contributor

    QA handoff for merged #31774 (main bbfe55669a1440424914d45a283a1d0e36f722fa): please verify the reported public SDK contract and its failure/recovery controls for FulltextSearchBuilder.limit(0) is silently dropped. This isolated QA run inspected the issue and merged PR but did not run tests or a live MatrixOne service at this SHA because the existing resource guard left insufficient headroom. The PR's author-reported validation is separate evidence, not a result of this QA run.

  6. Ariznawlll commented on Oct 30, 2026

    @Ariznawlll
    CollaboratorAuthor

    结论

    测试不通过。LIMIT 0 已保留,但 issue 同时要求的显式 OFFSET 0 在 FulltextSearchBuilder 输出中仍被省略;该值被省略时通常不改变返回行,但不满足 issue 中明确提出的 SQL 构造契约。

    关键证据

    • 修复 PR fix(python): unify SDK query and analytics lifecycle contracts #31774 已合并,作者 XuPeng-SH;其合并提交是官方 main@4ca0d77748c1e5fdd03486492fc3ca82c9045288 的祖先。本次独立导入该完整 SHA 的 Python SDK 源码,Python 3.12,无需 MatrixOne 服务即可复现原 issue 的 builder 输出。
    • FulltextSearchBuilder(...).table('docs').columns(['body']).add_term('alpha').limit(5).offset(0).explain() 重复 3 次均只包含 LIMIT 5,缺少预期的 OFFSET 0;正常对照 limit(0) 包含 LIMIT 0,limit(5).offset(1) 包含 LIMIT 5 OFFSET 1,3/3 一致。当前源码 的 offset 分支仍使用真值判断。
    • 另在此前可构建的 main@43c6d84741d60838c28d2b93ab8ad4b6f922a678 的隔离 1 CN / 1 TN / 1 LogService 上,实际全文索引的 LIMIT 0/1/5 返回行数符合预期,3/3;该旧版服务结果不代表当前 main 服务已验证。

    待解决点

    • 请研发确认并修复 OFFSET 0 的显式输出契约;issue 还提及默认搜索模式和其他 WHERE 边界,本轮未完成这些场景的验证。
    • 当前 main 的服务构建仍被 [Bug]: main fails to build: bool returned as writeDisposition #31812 阻断;未运行最新 main 的真实服务、完整 SDK suite 或 MOTR CI,不把旧版服务结果当成当前版本的通过结论。
  7. added a commit that references this issue on Oct 30, 2026
    91dfab2
  8. XuPeng-SH commented on Oct 30, 2026

    @XuPeng-SH
    Contributor

    新修复转 QA:#31889 已合入 main,合并提交 91dfab2132c4c4fcd3f9a115dbfa968b196b8b14。

    所有相关分页入口均使用is not None保留显式OFFSET0;默认模式差异与调用方raw WHERE责任有文档,复用MATCH模式渲染。

    已核对 issue 正文、完整评论及当前合并源码/测试内容。历史失败按其原 SHA 保留;新修复直接覆盖上述残留,未发现适用于新修复的已验证反例或尚未完成的开发 follow-up。本轮仅源码/测试内容静态核对,没有运行 MatrixOne 服务或 SDK 回归;作者在 PR 内的运行结果是作者证据,不是本轮独立测试。转 Ariznawlll 继续验证,不代表验收通过。

    QA 待验范围:LIMIT0/5/None与OFFSET0/1精确SQL及真实行数、各入口默认搜索模式、raw WHERE边界。

  9. Ariznawlll commented on Oct 31, 2026

    @Ariznawlll
    CollaboratorAuthor

    结论

    测试通过。两种全文入口的默认模式不同,已在 SDK 文档中说明;raw WHERE 仍由调用方负责构造。

    关键证据

    • 2026-10-31 本地隔离双 CN、TN、LogService,服务和 SDK 源码均为官方 main@4f894474ad10e1b9dc338868145a118a71c1fa23,修复 fix(python-sdk): unify SQL, transaction and driver boundaries #31889 在祖先链。
    • 真实全文索引上检查 LIMIT 0/5/None 和 OFFSET 0/1 的 SQL 与实际返回行数,显式 0 均保留;LIMIT 0 返回 0 行,未限制的匹配返回 2 行,OFFSET 1 返回 1 行,各 3/3。测试表原有三行不变,每轮清理测试库。
    • 验证 FulltextSearchBuilder 默认 natural language、boolean_match 默认 Boolean,以及调用方提供的 id = 1 raw WHERE 对实际结果的作用;差异和 raw WHERE 责任见 SDK docs/async-analytics-and-execution.md 及 docs/design/sdk-quality-extensions-wave2.md。
    • 真实索引回归见 MOTR #298 的 issue_31403_fulltext_pagination.py(提交 a6119756);该 PR 尚未合入,完整 suite 未运行。

    待解决点

    • 无。
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

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions