[Bug]: Python SDK Session Stage helpers escape transaction: LOAD survives rollback and EXPORT misses uncommitted rows
Maintainers usually reply within 1 day
@XuPeng-SH is already working on this.
Since Nov 26, 2026.
- #33326 by @MatrixAdventurer — closed without merging
Assessment
This issue has not been assessed yet.
Description
Is there an existing issue for the same bug?
- I have checked the existing issues.
Version Information
matrixone-python-sdk0.1.16, source checkout from mainc0cef5c9cce2164fedd201c188bfffe4d2d09a96(clients/python)- Python 3.12.3, SQLAlchemy 2.0.43, PyMySQL distribution 1.1.2, aiomysql 0.3.2
- Server: self-built MatrixOne main at the same commit;
version() = 8.0.30-MatrixOne-v1.3.0,git_version() = c0cef5c
Steps to Reproduce
A Stage obtained through session.stage.get() does not retain the Session executor. This causes two transaction-visibility failures: LOAD survives Session rollback, and EXPORT cannot see the Session's uncommitted writes.
Minimal synchronous reproduction (the async equivalents are described below):
import csv
import tempfile
from pathlib import Path
from matrixone import Client
class RollbackProbe(Exception):
pass
client = Client(sql_log_mode="off")
client.connect(
host="127.0.0.1", port=6001,
user="root", password="111", database="sdk_test",
)
client.execute("DROP TABLE IF EXISTS stage_tx_repro")
client.execute("CREATE TABLE stage_tx_repro (id INT PRIMARY KEY, name VARCHAR(30))")
with tempfile.TemporaryDirectory() as td:
client.stage.create("stage_tx_repro", f"file://{td}/")
Path(td, "rows.csv").write_text("1,alice\n2,bob\n", encoding="utf-8")
# 1. LOAD through the Stage object returned by the Session.
try:
with client.session() as session:
session.stage.get("stage_tx_repro").load_csv("rows.csv", "stage_tx_repro")
raise RollbackProbe() # rolls back the Session
except RollbackProbe:
pass
count = client.execute("SELECT COUNT(*) FROM stage_tx_repro").fetchall()[0][0]
print("rows after rollback:", count) # actual: 2; expected: 0
# 2. EXPORT through the Stage object returned by the Session.
client.execute("DELETE FROM stage_tx_repro")
client.execute("INSERT INTO stage_tx_repro VALUES (1, 'committed')")
try:
with client.session() as session:
session.execute("INSERT INTO stage_tx_repro VALUES (2, 'uncommitted')")
session.stage.get("stage_tx_repro").export_to_csv(
"out.csv", "SELECT id FROM stage_tx_repro ORDER BY id"
)
with Path(td, "out.csv").open(newline="", encoding="utf-8") as stream:
ids = [int(row[0]) for row in csv.reader(stream) if row and row[0] != "id"]
print("exported ids:", ids) # actual: [1]; expected: [1, 2]
raise RollbackProbe()
except RollbackProbe:
pass
The direct Session managers are positive controls:
- Replacing the Stage LOAD with
session.load_data.read_csv_stage(...)leaves 0 rows after rollback. - Replacing the Stage EXPORT with
session.export.to_csv_stage(...)exports [1, 2], including the uncommitted row.
Async has the same defect:
async with async_client.session() as session:
stage = await session.stage.get("stage_tx_repro")
await stage.load_csv("rows.csv", "stage_tx_repro")
# After Session rollback: 2 rows remain; direct async Session manager leaves 0.
async with async_client.session() as session:
await session.execute("INSERT INTO stage_tx_repro VALUES (2, 'uncommitted')")
stage = await session.stage.get("stage_tx_repro")
await stage.export_to_csv("out.csv", "SELECT id FROM stage_tx_repro ORDER BY id")
# Exports [1]; direct async Session manager exports [1, 2].
Each LOAD and EXPORT reproduction was run in two fresh Python processes with unique databases, stages, and tables. Results were identical in both rounds.
Actual Behavior
| Execution path | Rows remaining after LOAD + rollback | IDs exported before rollback |
|---|---|---|
| Native PyMySQL, one connection | 0 | [1, 10] |
| Direct sync Session manager | 0 | [1, 20] |
| Stage object from sync Session | 2 | [1] (expected [1, 30]) |
| Direct async Session manager | 0 | [1, 40] |
| Stage object from async Session | 2 | [1] (expected [1, 50]) |
For EXPORT, rolling back the Session afterwards leaves only the originally committed row in the base table. Thus the missing row in the CSV is not evidence that the INSERT was committed or visible globally; the Stage helper read through a different connection/transaction.
The native controls use the corresponding server SQL on one PyMySQL connection:
LOAD DATA INFILE 'stage://...'followed byROLLBACKleaves 0 rows.- An uncommitted INSERT followed by
SELECT ... INTO OUTFILE 'stage://...'exports both the committed and uncommitted rows.
Expected Behavior
A Stage object returned by a Session-bound StageManager should operate on that Session's executor:
load_csv()must join the current transaction, so Session rollback removes the loaded rows.export_to_csv()must use the current transaction's visibility and include its uncommitted writes.- Sync and async should have the same semantics as their direct Session managers and the native single-connection controls.
Additional information
The ownership loss is visible in clients/python/matrixone/stage.py:
BaseStageManager._process_get_result()constructsStage(..., _client=self.client)and does not propagateself.executor.Stage.load_csv()constructsLoadDataManager(self._client).Stage.export_to_csv()constructsExportManager(self._client).
Consequently, these helpers fall back to Client-managed pooled/autocommit connections instead of the Session connection. The Stage object should retain the owning executor and pass it to the load/export managers; Client-owned Stage objects should retain their existing behavior.
Other Stage load/export convenience methods share the same ownership pattern, but only load_csv() and export_to_csv() are claimed as reproduced here. After the error/rollback paths, both sync and async clients remained usable (SELECT 42 succeeded).
- Dominant language
- Go
- Stars
- 1.9k
- Forks
- 312
- Avg merge
- 22h 59m
- Merged PRs (30d)
- 736
Getting set up
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from matrixorigin/matrixone
-
kind/bug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
matrixorigin/matrixone#33363 ·
Maintainers usually reply within 1 day
-
kind/bug
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
matrixorigin/matrixone#33362 ·
Maintainers usually reply within 1 day
-
SLEEP rejects NULL and negative durations that MySQL acceptsPossibly taken @XuPeng-SH claimed this 7 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
matrixorigin/matrixone#32653 ·
Maintainers usually reply within 1 day
-
[Bug]: TestChangeWatchProxy loses its first tenant connection during PingContext in Ubuntu CIPossibly taken @XuPeng-SH claimed this today. Openkind/bug needs-triage
matrixorigin/matrixone#33371 · 1 assignee ·
Maintainers usually reply within 1 day
-
[Bug]: TestDaemonClaimSQLRoundTrip exhausts its shared deadline during the stale claim update in Ubuntu CIPossibly taken @XuPeng-SH claimed this today. Openkind/bug needs-triage
matrixorigin/matrixone#33370 · 1 assignee ·
Maintainers usually reply within 1 day
All issues in matrixorigin/matrixone
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
zalando/postgres-operator#3257 ·
Maintainers usually reply within 2 days
-
[inputs.internal] README lists go_version tag on internal_gather instead of internal_agentPossibly taken @cvas22 claimed this today. Open
Difficulty 1/5 Under an hour Newbie friendliness 90/100
influxdata/telegraf#20264 ·
Maintainers usually reply within 1 day
-
[Bug] Standalone migration breaks existing Ingress routes using the envoy-http Service port nameOpenaccepted bug wg/enterprise-environment
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
vllm-project/semantic-router#7483 · 1 comment ·
Maintainers usually reply within 1 day
-
needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
stacklok/toolhive-catalog#2076 ·
Maintainers usually reply within 1 day