Skip to content

fix(python): quote JSON object keys in bracket access - #30871

Merged
XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/fix-30765-json-member-paths
Oct 22, 2026
Merged

XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/fix-30765-json-member-paths

Conversation

@XuPeng-SH

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • 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.

@XuPeng-SH
XuPeng-SH requested a review from aptend as a code owner October 22, 2026 14:49
@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 →

@mergify mergify Bot added the kind/bug Something isn't working label Oct 22, 2026
@XuPeng-SH

XuPeng-SH commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 41a930fec47ca0863ff53a0215a3d4de267dfd99

"interrupted"

@XuPeng-SH

XuPeng-SH commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor Author

mo-bot review · mo-bot-local · done

Commit: dcf46bdbd5a7a9fd65b23f4ea73869380d98ee2c

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

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-local · review

Commit: dcf46bdbd5a7a9fd65b23f4ea73869380d98ee2c

Assessment: approve

Reviewed the complete three-file delta and affected callers. The design correctly centralizes literal-member encoding in JSONPathElement, preserves SQLAlchemy binding, and restores projection dependency and identity contracts. Tests distinguish literal keys from traversal syntax and cover reuse, Unicode, controls, missing values and typed consumers. No actionable introduced defects remain.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1517-7f90-b3f9-c5f9f9e7031b · slot 0 · generation 1

Validation:

  • Focused offline suite: 80 passed on CPython 3.12.12 / SQLAlchemy 2.0.43; receipt checks/1792682441663253884-3.json matches json-offline-current.log and JUnit results.

  • Real MatrixOne integration: head produced 43 passes and three failures; exact-base SDK/tests produced 29 passes and the same three failures. A second head run excluding those baseline failures passed all 43 cases. Fixture table and database cleanup verified. Receipt checks/1792682574644492789-12.json matches online-driver.jsonl and retained Python logs.

  • Private-runtime preflight passed. Native provenance matched 200 current source inputs and five build outputs before integration execution.

  • Reused frozen exact-head CI successes for offline SQLAlchemy 1.4, 2.0 and 2.1 configurations; pending and skipped checks were not counted as passes.

  • Source remained unchanged. Commands, fingerprints, exits, logs and 54 exact-base files were reconciled in /home/xupeng/.local/state/mo-bot/jobs/0a0fca83a48652fb3c5fec48/attempt-1/validation-audit.json; review rationale is retained alongside it in review-notes.json.

Limitations:

  • The full online file is not green: test_extract_with_filter, test_json_replace_only_existing and test_filter_with_dict_syntax fail identically on base and head.

  • Fresh local online validation covered SQLAlchemy 2.0.43. Author-only results without retained artifacts were not treated as independently verified evidence.

  • No performance benchmark was run. Added work is proportional to key length during construction and initial quoted-path parsing; existing constant-path caching preserves per-row traversal behavior.

  • Linked issue text was not supplied; its behavioral contract was assessed from the frozen PR description and reproductions.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Python SDK JSON paths containing quotes break SQL statement boundaries

1 participant