Skip to content

fix(python-sdk): unify SQL, transaction and driver boundaries - #31889

Merged
XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/python-sdk-assigned-round2
Oct 30, 2026
Merged

XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/python-sdk-assigned-round2

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Oct 30, 2026 •

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:

Closes #30242
Closes #31149
Closes #30059
Closes #31845
Closes #31840
Closes #31404
Closes #31403
Closes #31400
Closes #31399
Closes #31394

What this PR does / why we need it:

Repair the shared Python SDK boundaries behind the ten assigned reports in one change. A duplicate-key COMMIT reply now reports a rejected write with committed=False; a lost successful reply remains unknown. All search builders quote MATCH identifiers correctly, preserve explicit zero pagination, and share safe native mode rendering. Vector index creation and deletion share validation and execution instead of swallowing failures in repeated paths.

  • Repair async ORM bytes binding at the common dialect/physical-connection boundary. Install one instance-local hexadecimal binary encoder per connection, preserving the original nonbinary encoder and module globals. Move the existing pre-ping compatibility setting to the actual engine/pool owner so warmed adopted pools work with SQLAlchemy 2.0.43. Keep PyMySQL 1.2.3 supported; exclude broken aiomysql import versions 1.2.1/1.2.2 and temporarily cap below the announced 1.3 removal. Pin and assert the exact regression driver tuple in CI. No per-SQL probe.
  • Keep the existing analytics transaction and cleanup owners. Only a non-invalidated SQLAlchemy/PyMySQL (including aiomysql) IntegrityError 1062 at COMMIT is classified as rejected. Preserve the original cause/errno, phase and row count. Transport failures, invalidated errors and cancellation retain an unknown outcome. Discard failed connections; add no SQL probes, retries or workers.
  • Route the public complete-SQL builder and all convenience helpers through the existing lexical/type renderer. Preserve qmark-only builder semantics (including modulo expressions), strict arity and bound build() output. Reject orphan filter parameters even from empty iterators before UPDATE/DELETE generation, and render vector values through the existing literal owner. This closes the shared residual path in [Bug]: Python SQL builder corrupts quoted placeholders and typed values #31149/[Bug]: Python SDK substitutes parameters inside SQL literals and corrupts named prefixes #30059.
  • Render MATCH column components consistently across all four entry points, preserving qualified strings and atomic SQLAlchemy column names. Reuse one expression for score and filter. Preserve every native mode, including BM25 and natural-language query expansion, and reject invalid modes in the raw-mode builders. Document the intentional default-mode differences and caller-owned raw SQL fragments.
  • Validate vector numeric options on construction and later assignment before setup/DDL. Preserve None, empty metric defaults and future safe index keywords; leave algorithm-specific limits to the server. Share quoted create/drop paths across the three index classes and manager drop. Class/instance execution now raises the original error instead of printing and returning False.
  • Compile vector DDL through the SQLAlchemy identifier preparer so schema_translate_map reaches the physical database and percent characters survive the real PyMySQL wire path. Keep MatrixOne reserved identifiers quoted with a compiler-local policy, preserving Table metadata, dialect globals and standalone SQL identity. No per-query work is added.
  • Remove the global Select.with_snapshot import side effect. Export with_snapshot(statement, name) and retain select(..., snapshot=...). Applications retaining the method spelling explicitly call enable_snapshot_method() at startup; it is idempotent and refuses to overwrite another owner. Migrate consumers and examples without adding an automatic opt-in.
  • Raise the supported SQLAlchemy floor to the verified 1.4.54 across metadata, installation files and documentation, and add an exact-minimum CI cell/assertion. SQLAlchemy 1.4.24 fails cancellation/escaped-binding controls; this does not claim it was the last failing patch.
  • Verify the account metadata fix already present from fix(python): enforce CSV export format and preserve user account metadata #31802 instead of adding a second mapper. Cover reordered, missing optional, added, case-varied, duplicated and missing required columns, plus actual sync/async get/list and native SHOW ACCOUNTS readback.

Validation:

  • Full no-skip offline contracts on SQLAlchemy 1.4.54 (Python 3.8), 2.0.43 (Python 3.12), and 2.1.6 (Python 3.13); final driver ownership controls are included in the installed-wheel runs below.
  • Three fresh installed-wheel environments each passed 1,011 contract/consumer tests with no skips: Python 3.8 / SQLAlchemy 1.4.54 without Arrow; Python 3.9 / SQLAlchemy 2.0.55 / Arrow 21; Python 3.12 / SQLAlchemy 2.0.43 / aiomysql 0.3.2 / PyMySQL 1.2.3. Verified every packaged SDK Python file against source and the dependency constraints. Wheel/sdist builds and Twine checks pass.
  • Owned one-CN source fixture at kernel base d39d8a4: 26 core native checks plus targeted follow-ups cover rejected/unknown COMMIT outcomes, real packet-proxy lost acknowledgements, import/upload cleanup, reserved-name MATCH, BM25, IVF/HNSW DDL, historical reads and account metadata. Public SQL builders also round-trip date/binary/Unicode/NUL values, mutation scope and modulo expressions in both SQL modes.
  • Exact 2.0.43 / 0.3.2 / 1.2.3 driver tuple passes native ORM bytes/NULL readback and repeated pre-ping for managed and warmed adopted engines in both SQL modes. A separate native two-engine/shared-pool control verifies the actual pool ping owner. Repeated the affected native async analytics fault cases after the connection-owner change; zero skips.
  • Existing analytics offline checks: 101 passed, 213 explicitly server-only skips; those skips are not counted as online validation. Incremental Black and fatal flake8 cover changed owners/tests. Python has no applicable Go race detector; existing async cancellation/worker/physical-connection tests, deterministic ownership controls and real network faults provide the relevant concurrency evidence. No Go changes.
  • Rebased onto main bc168358728a, retaining the separate CI matrix-contract correction. Current-code DDL/release/search/vector consumers: 426 passed, zero skipped per environment on SQLAlchemy 1.4.54, 2.0.43 and 2.1.6. Fresh installed wheels byte-match every SDK module and pass the same 426 tests on 1.4.54, 2.0.55/Arrow21 and 2.0.43/PyMySQL1.2.3. The 20 CI scope tests and incremental Black/fatal flake8 pass.
  • An owned one-CN fixture built from current kernel base bc168358728a passes four native DDL checks, including logical and default-schema translation, percent-containing database/index names verified via SHOW INDEX, create/drop, unchanged rows and existing native failure controls; zero skips. Fixture teardown completes successfully. This is source-fixture evidence, not release-binary certification.
  • Independent gpt-6.1-terra / max design and final overall review; material findings corrected and affected checks repeated.

Compatibility: the dependency floor, explicit snapshot-method opt-in and raised index execution errors are intentional corrections documented in the SDK guide. No additional per-query round trip is introduced. Native tests use an owned source fixture, not historical 4.2.5 or other release-binary certification. The fixture could not establish a GBK connection (2013 before encoding); actual-driver GBK/both-mode hex tests pass without claiming a native GBK result. This fixes the bytes compatibility path, not the entire upstream string-encoding advisory; dotted-name fulltext index creation is a separate native limitation, so only its SDK lexical rendering is asserted offline. Remote CI remains pending.

@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 kind/bug Something isn't working kind/enhancement kind/documentation Improvements or additions to documentation kind/test-ci kind/refactor Code refactor kind/api-change labels Oct 30, 2026
@XuPeng-SH

XuPeng-SH commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 4773de5e7eb9be683fd5f9a1b21c78bd6749d600

Review belongs to an older commit; it is not a review of the current head.

@XuPeng-SH

XuPeng-SH commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 436b9b4dcc41f67079596413b94c9f0f8e7acbe3

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: 436b9b4dcc41f67079596413b94c9f0f8e7acbe3

Assessment: request_changes

Two vector DDL regressions remain despite the passing offline suite. Both were reproduced against the merge-base.

Model: gpt-6-astra / xhigh

Session: 01a1869d-820c-7212-9788-aecfb86a4141 · slot 0 · generation 2

  • P2 clients/python/matrixone/sqlalchemy_ext/vector_index.py:1009: Execute CreateIndex for a table with schema='template' on a connection using schema_translate_map={'template': 'tenant_actual'}.
    Impact: Reading table.schema directly bypasses SQLAlchemy's schema translation. The index targets the original database, potentially modifying the wrong table or failing during schema creation. Preserve schema-aware formatting while forcing identifier quoting.
    Evidence: probes/vector_ddl_boundaries.py uses real SQLAlchemy Connection.execute with a deterministic transport. vector-ddl-probe.log shows HEAD targeting template.vectors, while the merge-base correctly targets tenant_actual.vectors under both format and pyformat.

  • P2 clients/python/matrixone/sqlalchemy_ext/vector_index.py:1022: Execute compiled vector-index DDL with a percent-containing index name, such as ix%name, ix%s or ix%%name.
    Impact: sql_object_name bypasses the dialect preparer's percent escaping. Driver formatting can fail or silently change the index name. Restore dialect-aware escaping for compiled DDL while retaining correct standalone SQL rendering.
    Evidence: vector-ddl-probe.log records ix%name failing before transport, ix%s becoming ix{} with pyformat, and ix%%name becoming ix%name. The same real SQLAlchemy/PyMySQL dispatch probe preserves every name at the merge-base; ordinary-name controls pass at both revisions.

Validation:

  • Isolation preflight passed; receipt checks/1793357612636622390-3.json.

  • Full offline suite: 2787 tests and 95 subtests passed, no skips, on Python 3.13.5 / SQLAlchemy 2.0.43 / aiomysql 0.3.2 / PyMySQL 1.2.3. Receipt checks/1793357642181275349-3.json; offline-2.0.43.log and provenance retained.

  • Baseline/candidate DDL probe confirmed both regressions; receipt checks/1793357740727492551-3.json and vector-ddl-probe.log.

  • All 20 CI scope tests passed; receipt checks/1793357766556935537-3.json.

  • Final audit verified frozen sources, unchanged checkout, complete discussion coverage and receipt/log correspondence; checks/1793357859268795508-3.json.

Limitations:

  • DDL reproductions exercise compilation and driver formatting with a simulated transport, not a native MatrixOne server.

  • Native-server validation remains author-reported. The frozen CI snapshot reports successful Python offline jobs and a skipped online job.

@XuPeng-SH

XuPeng-SH commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 637b186c3097b116dfaf0f7f9f017b1ca8ef04be

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: 637b186c3097b116dfaf0f7f9f017b1ca8ef04be

Assessment: approve

Both prior vector-DDL findings are resolved: schema translation is preserved and percent-bearing identifiers retain their wire identity. No actionable findings remain.

Model: gpt-6-astra / xhigh

Session: 01a1869d-820c-7212-9788-aecfb86a4141 · slot 0 · generation 2

Validation:

  • 376 focused tests passed with zero skips on each of SQLAlchemy 1.4.54, 2.0.43 and 2.1.6, including 60 DDL regression cases per version. Receipts and logs are mapped in validation-index.json.

  • The initial SQLAlchemy 2.1.6 environment failure resolved after installing the SDK wheel; all 60 packaged SDK modules match the frozen source.

  • Reviewed all 43 changed files and reconciled all five discussion keys. Verified unchanged prior coverage across 378 SDK/CI files.

  • Final audit passed; source remains unchanged. Review records and validation evidence are retained in the diagnostic directory.

Limitations:

  • Local checks used Python 3.13.5 and deterministic driver transport, not a native server. Native and older-Python qualification remain author-reported evidence.

  • The frozen CI snapshot has online tests skipped.

@XuPeng-SH
XuPeng-SH merged commit 91dfab2 into matrixorigin:main Oct 30, 2026
@XuPeng-SH
XuPeng-SH deleted the codex/python-sdk-assigned-round2 branch October 30, 2026 19:48

This branch was successfully deployed

No deployments
ci — 35861ef4 Deployed Oct 30, 2026 by XuPeng-SH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment