Skip to content

fix(python): enforce CSV export format and preserve user account metadata - #31802

Merged
XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/python-sdk-export-format-20261030
Oct 30, 2026
Merged

XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/python-sdk-export-format-20261030

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 #31736
Fixes #31394

What this PR does / why we need it:

export.to_csv() currently lets a recognized filename suffix silently select JSONL or Parquet. Specify FORMAT 'csv' in the shared SQL builder used by sync/async clients and Stage shortcuts. Normal and unknown suffixes produce CSV; conflicting recognized suffixes receive the server's existing format-mismatch error. No second suffix parser, capability probe or export retry is added.

The account mapping reported in #31394 was fixed by #31774, but user creation and listing still extract the current account from the first SHOW ACCOUNTS column. Pass the result metadata through the existing shared account converter for those four sync/async consumers. Preserve empty/multiple-account and legacy rows-only behavior, without constructing Account objects for every visible tenant just to determine the current account.

Validation:

  • Full Python offline/analytics: 2686 passed, 206 skipped, 95 subtests passed. Skips are not native coverage.
  • Account/export contracts: 141 passed each on Python 3.8 / SQLAlchemy 1.4.24 with minimum drivers; Python 3.8 / 1.4.54; Python 3.9 / 2.0.55.
  • Configured fatal flake8, Black and git diff --check pass for the complete four-file delta. Python-only change; no applicable Go race detector. Sync/async public entry points are exercised.
  • Owned two-CN integration: 18 cases passed across sync/async and Stage paths. Actual CSV bytes/readback cover comma, embedded quote, Unicode and NULL; all ten conflicting-suffix calls reject with a format-mismatch error, source rows remain unchanged and subsequent queries succeed. Before the fix, the public CSV API's .jsonl output was independently parsed as JSON. The owned fixture exited successfully.
  • That integration fixture uses the earlier task-owned kernel with unchanged relevant OUTFILE grammar/format-validation paths; it is not an exact-main native certification. Existing CSV-header behavior is independently tracked and is outside this format fix.

Compatibility: explicit OUTFILE FORMAT requires server grammar introduced by #23369 (also used by the existing JSONL exporter). Older unsupported servers return an error; the SDK does not retry an export whose outcome could be uncertain. This adds no SQL round trips or ordinary-query probes.

Actual gpt-6.1-terra / max design and final overall review are recorded for this change. Remote CI remains pending.

@XuPeng-SH
XuPeng-SH requested a review from aptend as a code owner October 30, 2026 02:00
@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/test-ci kind/refactor Code refactor labels Oct 30, 2026
@XuPeng-SH

XuPeng-SH commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: e25ac4d1f6268cc9c467225de54adf08cd779bcc

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: e25ac4d1f6268cc9c467225de54adf08cd779bcc

Assessment: approve

The changes correctly reuse existing CSV-format and account-metadata owners. All affected consumers were reviewed; no actionable findings remain.

Model: gpt-6-astra / xhigh

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

Validation:

  • 141 focused account/export tests passed with zero skips.

  • Diagnostics passed for eight SQLAlchemy result-consumer paths, account boundary controls and six export error paths.

  • Reused seven successful Python offline CI matrix jobs at the assessed head.

  • Verified explicit CSV grammar and dispatch in frozen 4.1.0 and 4.2.5 release sources.

  • Source remained unchanged. Discussion coverage and command/log/receipt reconciliation are saved in discussion-assessment.json and validation-evidence.json.

Limitations:

  • Linked issue bodies were unavailable.

  • No live MatrixOne execution was performed locally; author-reported integration counts were not independently verified.

  • The supplied snapshot shows online CI skipped and aggregate CI Required pending; neither is counted as a pass.

@XuPeng-SH
XuPeng-SH merged commit 43c6d84 into matrixorigin:main Oct 30, 2026
28 checks passed
@XuPeng-SH
XuPeng-SH deleted the codex/python-sdk-export-format-20261030 branch October 30, 2026 02:13
XuPeng-SH added a commit that referenced this pull request Oct 30, 2026
## What type of PR is this?

- [x] API-change
- [x] BUG
- [x] Improvement
- [x] Documentation
- [ ] Feature
- [x] Test and CI
- [x] 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 #31149/#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 #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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

1 participant