Skip to content

fix(python-sdk): bind JSON path strings safely - #30766

Merged
mergify[bot] merged 2 commits into
matrixorigin:mainfrom
MatrixAdventurer:fix/python-json-path-literals-20261022
Oct 21, 2026
Merged

mergify[bot] merged 2 commits into
matrixorigin:mainfrom
MatrixAdventurer:fix/python-json-path-literals-20261022

Conversation

@MatrixAdventurer

@MatrixAdventurer MatrixAdventurer commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

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

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Related to #30765. No automatic issue closure is requested.

What this PR does / why we need it:

A valid JSON path such as $."owner's" currently breaks the SQL statement because six JSON helpers construct a raw literal_column from the path. Keep paths as string values using SQLAlchemy's ordinary literal(path), letting the existing dialect/driver escape them. Explicit literal_binds=True compilation still renders escaped literals. Ordinary binding also preserves SQLAlchemy 1.4 compatibility and executemany.

The complete fix changes three files (+76/-14): the existing JSON helpers, their offline suite, and their online suite. No dependencies, generated source, kernel behavior or schema change. This is an ordinary R2 client encoding fix; no new state, cache, resource owner, protocol or feature design is introduced.

Verification

  • Final head: eac18da85008a93ae4b770a6f86bcd4af9e7e6d0; base: main 57681d4d17a98146f5e722fabe3da4dfc3a7ddec. No exact upstream dev exists; main is used as explicitly authorized.
  • Native SQLite/SQLAlchemy boundary regression against unchanged production: 12 failed / 18 passed. The final JSON test file passes 50/50, including three native JSON mutation executemany cases that verify both written rows.
  • Isolated MatrixOne validation is SUCCESS. Each SQLAlchemy version uses a test-owned official MatrixOne v4.2.5 container and the same six public Client.execute roundtrips:
SQLAlchemy Original production Fixed production Complete offline suite
1.4.54 6 failed (SQL 1064) 6 passed 1258 passed + 86 subtests
2.0.55 6 failed (SQL 1064) 6 passed 1254 passed + 86 subtests
2.1.6 6 failed (SQL 1064) 6 passed 1262 passed + 86 subtests
  • The red oracle rejects setup errors and skips; candidate source is restored before green/offline checks. Fatal Flake8, wheel/sdist builds and Twine checks pass in all three cells. This is six selected online regressions, not the entire online suite or kernel CI.
  • Final local offline matrix matches those counts; compileall and diff check pass. Independent review approved the tested production head and independently fetched the remote full tree.
  • Validation source 8541db1 and final head have the identical complete clients/python tree b015c54087ab3fd340eeec402a451a3019dc26a2. The intervening base commits only alter kernel backup and UT scheduling; SDK source, dependencies, test oracles and SDK CI are unchanged. Evidence is reused under the repository's semantic-validity rule; final remote synchronization was independently fetched and explicitly Approve.
  • Product tree 4117c874feebbb7371a429b1ef432b410cf71094 equals local fixed commit fc98f4c2307d438c62cc4ba119fd3af9f39988e4. Earlier tested head remains archived in the own fork. The verification workflow is only on an independent fork execution branch, not in this product PR.
  • Authenticated user, own fork relationship and push permission were verified. Only MatrixAdventurer/matrixone:fix/python-json-path-literals-20261022 was updated, with an expected-SHA lease; no default branch was written. Issue [Bug]: Python SDK JSON paths containing quotes break SQL statement boundaries #30765 is assigned to actual login XuPeng-SH. PR assignee and requested reviewer XuPeng-SH have now been read back.
  • Upstream MatrixOne ALL CI 39692878618: all six SDK Python/SQLAlchemy matrix jobs and CI Required succeeded. Kernel/upgrade/BVT and the manually dispatched full online job were intentionally path-skipped, not claimed passed. PR is ready for review. No merge, deployment or issue closure is performed. Read-only checks and all branch/commit operations are by the signed execution subject.

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

Keep six JSON helper path arguments inside string values, including quoted member names. Preserve SQLAlchemy 1.4 compatibility and executemany, with native SQL boundary and online roundtrip regressions.

Rebase onto main 57681d4; the complete clients/python tree is unchanged from verified candidate 8541db1.

Related to matrixorigin#30765.

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

Copy link
Copy Markdown
Contributor Author

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

发布后固定交付记录:head eac18da,3文件+76/-14。独立review对最终远程head再次明确Approve,确认parent57681d4、全树与本地固定提交一致,完整PythonSDK树与真实三版本MatrixOne RED/GREEN及全量offline/打包已测版本一致。没有未处理审查阻塞。

已读回PR正文与预检内容完全相同、LF换行及模板段落正确。产品PR没有验证workflow或临时生成物;必要offline/online回归完整保留。Issue #30765 的XuPeng-SH assignee已读回,PR暂draft等待上游正式required CI;通过后再指派PR并请求该负责人审阅并读回。不合并、不关闭Issue。所有分支归档、expected-SHA更新、PR创建与只读核验主体同上署名。

@mergify mergify Bot added the kind/bug Something isn't working label Oct 21, 2026
@MatrixAdventurer
MatrixAdventurer marked this pull request as ready for review October 21, 2026 23:22
@mergify mergify Bot added the kind/test-ci label Oct 21, 2026
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

Copy link
Copy Markdown
Contributor Author

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

上游正式门禁与负责人交付已完成(head eac18da 未变化):MatrixOne ALL CI #39692878618 的6个Python/SQLAlchemy矩阵job均SUCCESS,CI preflight及CI Required聚合门禁SUCCESS;Iceberg adapter module tidy SUCCESS,E2E按路径SKIPPED。内核/升级/BVT与完整在线job按路径/手动触发条件SKIPPED,未冒充通过。

独立终审Approve、真实MatrixOne三版本各6项RED→GREEN、全量offline与打包证据见正文和Issue。无新inline thread或requested changes。全部规定门禁通过后,已将PR转ready、assign XuPeng-SH并请求其审阅;重新读取GitHub确认draft=false、assignees含XuPeng-SH、requested reviewers含XuPeng-SH。正文同步实际结果。以上无正文的状态/指派/审阅请求与只读核验均由本署名主体执行;不合并、不部署、不关闭Issue。

@XuPeng-SH

XuPeng-SH commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-xupeng · done

Commit: eac18da85008a93ae4b770a6f86bcd4af9e7e6d0

Review completed. Read the assessment.

@XuPeng-SH

XuPeng-SH commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · superseded

Commit: eac18da85008a93ae4b770a6f86bcd4af9e7e6d0

already-reviewed

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-xupeng · review

Commit: eac18da85008a93ae4b770a6f86bcd4af9e7e6d0

Assessment: approve

Reviewed the complete three-file delta, callers, compatibility, test coverage and supplied comments. The fix correctly delegates JSON-path escaping to SQLAlchemy without adding another execution path. No actionable defects found.

Model: gpt-6-astra / xhigh

Session: 01a14d34-4e51-79a3-a62d-6c9c16279dc8 · slot 0 · generation 0

Validation:

  • Verified frozen head/base, complete patch, clean source and declared SDK/product tree hashes.

  • Isolation preflight passed. All 50 JSON offline tests passed on each of SQLAlchemy 1.4.54, 2.0.55 and 2.1.6, including cached bindings and two-row executemany mutations.

  • Thirty additional literal-rendering cases passed through the public SQL-string compiler and SQLite parser; MatrixOne dialect bind compilation also passed.

  • Matched commands, source fingerprints, successful exit receipts, logs and JUnit counts. Evidence retained in /home/xupeng/.local/state/mo-bot/jobs/fba5805d3b614c5226ed2343/attempt-1/validation-manifest.json.

  • Inspected CI wiring and the frozen snapshot reporting six successful SDK offline matrix jobs and CI Required.

Limitations:

  • No live MatrixOne roundtrip or full offline suite was rerun locally. Author-reported online results lack retained execution logs in the supplied bundle and were not independently verified.

  • Local tests used Python 3.13.5; other Python versions are represented only by the frozen CI status snapshot.

  • The linked issue body was not supplied; review covered the behavioral contract stated in the PR.

@mergify mergify Bot added the queued label Oct 21, 2026
@mergify

mergify Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-21 23:34 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-10-21 23:37 UTC · at a538c4bccd367d227440721990a04695d6add842 · squash

This pull request spent 3 minutes 4 seconds in the queue, including 1 minute 49 seconds running CI.

Required conditions to merge

@mergify
mergify Bot merged commit a538c4b into matrixorigin:main Oct 21, 2026
@mergify mergify Bot removed the queued label Oct 21, 2026
XuPeng-SH added a commit that referenced this pull request Oct 22, 2026
## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes #30765.

## What this PR does / why we need it:

Python SDK bracket access still concatenates object keys as bare
JSONPath syntax after #30766 fixed SQL parameter binding.
`data["owner's"]` raises an invalid-path error, while `data["x.y"]`
silently reads nested `x.y` instead of the literal member named `x.y`.

Encode every first and nested member with the standard library JSON
string encoder, retaining actual UTF-8 for non-BMP characters. Existing
SQLAlchemy binding remains responsible for SQL boundaries. All default,
text, numeric, boolean and comparison readers consume the same correctly
quoted path. No manual identifier grammar, compatibility branches, cache
or server/protocol changes are added. Encoding is linear in key length
during expression construction; no per-row work is introduced.

Default unlabelled projection also exposed existing SQLAlchemy
expression integration defects. Delegate FROM dependencies to the
underlying column/literal, restore inherited identity hashing for
anonymous labels, and remove the obsolete `_is_subquery` override.
Extend the existing offline/online JSON suites with discriminating
values, literal-versus-nested collisions, punctuation, quotes,
backslashes, empty names, control characters, Unicode, parent/sibling
reuse, missing/NULL values, typed predicates, and
ORM/table/alias/literal projection compilation. Stabilize four existing
order-dependent assertions with explicit ordering.

Validation on the final content (CPython 3.12.8, SQLAlchemy 1.4.54 /
2.0.43 / 2.1.6):

- Entire SDK offline suite: **1298 / 1294 / 1302 passed**, plus 86
subtests per version.
- Owned one-CN MatrixOne instance: **43 online JSON tests passed per
version**, including all 14 new cases. Fixture table/database cleanup
and cluster shutdown verified.
- Three unchanged online tests were separately reproduced on the exact
unmodified base (3 failed, 29 passed) and explicitly deselected for
these runs: `test_extract_with_filter`,
`test_json_replace_only_existing`, and `test_filter_with_dict_syntax`.
Existing raw-JSON/string comparison behavior and the numeric-mutation
expectation are outside this member-path correction; the full online
file is not claimed green.
- Bound and literal-rendered SQL transport checks for nine independently
specified paths, plus 64 independent expression trees compiled across
four workers, passed on all three versions.
- Configured fatal Flake8 checks over the SDK and changed tests, Black
on all changed files, and `git diff --check` passed.
- Go race instrumentation is inapplicable to this Python-only builder;
CPython has no corresponding race detector. The bounded concurrent
compilation check validates expression isolation. No Go production code
changes.
- Solution/design and final overall review use explicitly selected
`gpt-6.1-sol` with `xhigh` reasoning. Remote CI remains pending.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working kind/test-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants