Repository navigation
Description
Description
Python SDK 的 ORM subquery() 返回仅含 SQL 的字符串,却丢弃子查询已绑定的参数。把该子查询用于 join() 时,生成的 SQL 仍含 ?,外层参数列表却为空;合法的 DECIMAL 过滤 JOIN 不能执行。
Environment
- Branch:
main - Commit:
5fe08a3307e246e1ab9951ab690b50557af0f509 - Local isolated 1 LOG / 1 TN / 1 CN; SQL port 36601;
VERSION() = 8.0.30-MatrixOne-v1.3.0 - Python SDK 0.1.16, Python 3.11, SQLAlchemy 2.0.55
Steps to reproduce
# Existing table src(id INT PRIMARY KEY, amt DECIMAL(10,2)):
# rows (1,1.20),(2,2.30); Model is its SQLAlchemy mapped class.
from decimal import Decimal
inner = client.query(Model).select("id").logical_in("amt", [Decimal("1.20")])
sub = inner.subquery("s")
outer = client.query("src AS o").select("o.id", "o.amt").join(sub, "o.id=s.id")
print(inner._build_sql()) # ('SELECT id FROM src WHERE amt IN (?)', [Decimal('1.20')])
print(outer._build_sql()) # (... JOIN (SELECT id FROM src WHERE amt IN (?)) AS s ..., [])
print(outer.all())Actual behavior
QueryError: Query execution failed: Not enough SQL parameters.
Expected behavior
The derived-table JOIN should retain the inner parameter and return exactly (1, Decimal('1.20')).
Stability and controls
- Reproducer: sync 3/3 and async 3/3, each with fresh source tables; both returned
Not enough SQL parameters. - Same outer SQL executed with explicit
[Decimal('1.20')]returned row 1 in sync and async 3/3; direct literal SQL also returned row 1 in sync 3/3. - A JOIN over a non-parameterized SDK
subquery()returned row 1 in 3/3, isolating lost binds rather than JOIN support. - After each failure,
COUNT(*)=2,SUM(amt)=3.50, andSELECT 42returned(42); no rows changed.
Evidence
/private/tmp/mo-sdk-sqlbuilder-20261026/subquery_join_bind_probe.py and async_subquery_join_bind_probe.py (execute with /private/tmp/mo-sdk-py311-venv-20261026/bin/python). Each temporary database was dropped after confirming no tables remained.
Code analysis
clients/python/matrixone/orm.py:1076-1082 calls _build_sql() but discards its params, returning only the derived-table SQL string. BaseMatrixOneQuery.join() then stores this string; the unified builder has no way to include its binds. This is different from #31212 (parameter order within one WHERE list) and #30059 (literal substitution).
Regression coverage
Add an SDK online test for a bound DECIMAL or binary subquery embedded in JOIN, comparing exact rows to the same SQL with explicit binds; keep a no-bind subquery control and failed-query state check.
Activity
fix(python-sdk): unify query contracts and atomic manager operations (#…
XuPeng-SH commentedon Oct 26, 2026
Local SDK QA (2026-10-26): SDK source
28e8760905a7f39dba2ce436357ea75492f30512; isolated MatrixOne service binary83c1e23526fc0ed31188abd7fc2ca87cd3a6d4b3(SHA-2566bebe05311ae6438967a824641e3849fbbc9af298003177351794601edf14b4b). Passedtests/online/test_sdk_wave2_contracts.py::test_join_fk_and_binary_subquery[sync]and[async]. A derived query carrying Decimallogical_inand non-UTF8 binary filter parameters was joined from an outer query; it returned exactly(1, Decimal('1.20')). Rebuilding the same subquery was stable.Ariznawlll commentedon Oct 27, 2026
测试版本
420786e21566e5b9d5875e7d6a7f3102fd0761af;修复 PR fix(python-sdk): unify query contracts and atomic manager operations #31262 已 MERGED,merge commit28e8760905a7f39dba2ce436357ea75492f30512在该 main 的祖先链。8bd0f1f4c60cd0590c68cdbb2cbca31fc9d39d071ec367ab56d5c49b4eec327e。原问题验证
构造内层 ORM 查询,包含 Decimal
logical_in(amount,[1.20])与非 UTF-8 VARBINARY 谓词,封装为subquery('s')并从外层 JOIN;同步/异步均返回精确(id,amount)=(1,Decimal('1.20')),三轮通过。原来丢失绑定参数的衍生表路径未复现。Happy Path 覆盖
Unhappy Path 覆盖
(2,2.30)不会被意外带出;测试表删除后无残留。白盒验证
核对已合入回归源码中的 SDK 公开入口、返回值断言与真实服务执行结果;未修改产品源码,未运行全量 SDK suite 或 race。
回归测试
#31262 已包含
clients/python/tests/online/test_sdk_wave2_contracts.py::test_join_fk_and_binary_subquery[sync/async]。此为 Python SDK 行为,纯 SQL MOTR 不能替代;未新增 MO 或 MOTR PR。#31262 六个离线 SDK CI job 成功、在线 CI SKIPPED;本地在线执行是独立证据。测试证据
本地 JUnit:
/private/tmp/mo-six-qa-20261026/qa-night/sdk-contract-round-{1,2,3}.xml(每轮 70、失败/错误/跳过均 0),sdk-offline-round-{1,2,3}.xml(每轮 112、失败/错误/跳过均 0)。修复 PR:#31262 。测试结论
测试通过。