Repository navigation
Description
Description
Python SDK client.export.to_jsonl() silently writes CSV instead of JSON Lines when the accepted output path has a non-.jsonl suffix (for example .txt). The call reports success, so a consumer reading the documented JSONL format receives invalid content. The SDK does not specify an output-format clause; the server infers the format from the filename.
Environment
- MatrixOne official
main:5fe08a3307e246e1ab9951ab690b50557af0f509 - Isolated single-node LOG/TN/CN, SQL port 36601
- Repository Python SDK
0.1.16, Python 3.11, SQLAlchemy 2.0.55 - Test date: 2026-10-26
Steps to reproduce
CREATE DATABASE qa_sdk_export;
CREATE TABLE qa_sdk_export.t(id INT PRIMARY KEY, s VARCHAR(60));
INSERT INTO qa_sdk_export.t VALUES (1,'alpha'),(2,'beta');from matrixone import Client
import json
client = Client()
client.connect(host='127.0.0.1', port=36601, database='qa_sdk_export', on_connect=[])
client.export.to_jsonl('/tmp/sdk_output.txt', 'SELECT id,s FROM t ORDER BY id')
with open('/tmp/sdk_output.txt') as f:
rows = [json.loads(line) for line in f] # JSONDecodeErrorActual behavior
to_jsonl() succeeds but /tmp/sdk_output.txt contains CSV, including a header:
id,s
1,"alpha"
2,"beta"
Expected behavior
The JSONL API should produce valid JSON Lines regardless of a permitted output filename, or explicitly reject a filename it cannot support. It must not silently write another format. On the same server, SELECT id,s FROM t ORDER BY id INTO OUTFILE '/tmp/direct_output.txt' FORMAT 'jsonline' succeeds and writes {"id":1,"s":"alpha"} and {"id":2,"s":"beta"}. The SDK also writes valid JSONL when the path ends in .jsonl.
Stability and controls
- Reproducer: 3/3 fresh databases and distinct output files.
- Controls: SDK
.jsonlpath and direct SQL explicitFORMAT 'jsonline'with.txtpath both parse as two JSON objects in all rounds. - Failure path: an invalid SELECT raises
QueryError; the table still contains two rows and the connection remains usable.
Evidence
Local reproducible probe: /private/tmp/mo-sdk-export-20261026/export_probe.py; three runs' files are in the same isolated directory. The exact generated SDK SQL is SELECT id, s FROM t ORDER BY id INTO OUTFILE '.../sdk_1.txt' (no FORMAT clause).
Code analysis
clients/python/matrixone/export.py _build_jsonl_export_sql() documents JSONL output but returns only f"{query_sql} INTO OUTFILE '{output_path}'". This is the SDK-side missing format selection; the server's explicit-format path works.
Regression coverage
Test to_jsonl() with .jsonl and non-.jsonl permitted filenames. Parse every output line as JSON and compare complete values, not merely file existence or call success.
Activity
fix(python-sdk): unify query contracts and atomic manager operations (#…
XuPeng-SH commentedon Oct 26, 2026
Local SDK QA (2026-10-26): SDK source
28e8760905a7f39dba2ce436357ea75492f30512; isolated MatrixOne service binary83c1e23526fc0ed31188abd7fc2ca87cd3a6d4b3(SHA-2566bebe05311ae6438967a824641e3849fbbc9af298003177351794601edf14b4b). Passedtests/online/test_sdk_quality_contracts.py::test_export_content[txt]and[jsonl]. Both calls useto_jsonl(); each output line parsed as JSON and the full expected rows (including NULL) matched, including a.txtfilename. Focused SDK export contract against the older backend; not full-suite or new-kernel qualification.Ariznawlll commentedon Oct 26, 2026
测试版本
main;执行验收时的完整 commit:47652f7a1aa1d4a08bdab460191dc1b6e79209f3;本地mo-service与SELECT git_version()均对应47652f7a1a,二进制 SHA-256 为53b4b13293a17873112324277745247cddba28004accd1081096500636e89a24。28e8760905a7f39dba2ce436357ea75492f30512是上述 main 的祖先;这次验证使用该 main 下的 SDK 源码。127.0.0.1:47011;独立临时导出目录和测试库,未使用共享环境。日期:2026-10-27。原问题验证
按原报告使用
Client.export.to_jsonl()导出到非.jsonl的.txt文件。运行tests/online/test_sdk_quality_contracts.py::test_export_content连续 3 轮,每轮分别测试.txt与.jsonl(合计 6/6 通过,零 skip)。每一行都用json.loads解析,并严格比较实际三行:{"id":1,"label":"red"}、{"id":2,"label":"blue"}、{"id":3,"label":null}。.txt不再被静默写成 CSV;每轮采用新的表和文件名并清理。Happy Path 覆盖
.txt和.jsonl两种后缀均实际产出相同的 JSON Lines,值、行数、顺序及 JSONnull均核对,3/3 轮通过。test_async_public_export另外连续 3 轮、每轮 CSV/JSONL 两个异步导出分支,合计 6/6 通过;JSONL 的三行完整值和 CSV 头、三行内容均核对。Unhappy Path 覆盖
QueryError;随后源表COUNT(*)=3,同一客户端仍能SELECT 42,未把失败当成功,也未破坏数据或连接。白盒验证
此问题是 Python SDK 生成导出 SQL 时缺少显式格式的产品接口缺陷,不涉及 Go 并发内部路径;Go
-race不适用。定向在线用例和 SDK 全部必跑 native contracts 已在对应的真实服务上运行。回归测试
.jsonl后缀的逐行 JSON 与完整值;同文件的异步导出测试覆盖错误路径。无需将 SDK 接口测试伪装为 MOTR 静态 SQL 测试,也未向 MO 或 MOTR 新提 PR。qa-night/sdk-contract-run2/。PR fix(python-sdk): unify query contracts and atomic manager operations #31262 的 CI 中 SDK 离线矩阵及 CI Required 通过;该 CI 的在线部分未运行,以上在线结果来自本地,不声称完整仓库 CI。测试证据
python -m pytest -q tests/online/test_sdk_quality_contracts.py::test_export_content×3(每轮2 passed);test_async_public_export×3(每轮2 passed)。运行时启用MO_SDK_ONLINE=1并绑定上述隔离服务及导出目录;首轮环境准备中未设置该开关导致的 skip 不计入通过次数,设置后重跑如上。测试结论
测试通过。