Skip to content

[Bug]: Python SDK to_jsonl silently exports CSV for a non-jsonl filename #31202

Closed

Description

@Ariznawlll

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]  # JSONDecodeError

Actual 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 .jsonl path and direct SQL explicit FORMAT 'jsonline' with .txt path 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

  1. added this to the MO-202610 milestone on Oct 26, 2026
  2. added
    kind/bug
    on Oct 26, 2026
  3. added theissue type on Oct 26, 2026
  4. added a commit that references this issue on Oct 26, 2026
    28e8760
  5. XuPeng-SH commented on Oct 26, 2026

    @XuPeng-SH
    Contributor

    Local SDK QA (2026-10-26): SDK source 28e8760905a7f39dba2ce436357ea75492f30512; isolated MatrixOne service binary 83c1e23526fc0ed31188abd7fc2ca87cd3a6d4b3 (SHA-256 6bebe05311ae6438967a824641e3849fbbc9af298003177351794601edf14b4b). Passed tests/online/test_sdk_quality_contracts.py::test_export_content[txt] and [jsonl]. Both calls use to_jsonl(); each output line parsed as JSON and the full expected rows (including NULL) matched, including a .txt filename. Focused SDK export contract against the older backend; not full-suite or new-kernel qualification.

  6. Ariznawlll commented on Oct 26, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:官方 main;执行验收时的完整 commit:47652f7a1aa1d4a08bdab460191dc1b6e79209f3;本地 mo-service 与 SELECT git_version() 均对应 47652f7a1a,二进制 SHA-256 为 53b4b13293a17873112324277745247cddba28004accd1081096500636e89a24。
    • 修复:Python SDK PR #31262 已 MERGED,merge commit 28e8760905a7f39dba2ce436357ea75492f30512 是上述 main 的祖先;这次验证使用该 main 下的 SDK 源码。
    • 部署:本机隔离的 1 LOG / 1 TN / 2 CN,测试连接 CN1 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 覆盖

    1. .txt 和 .jsonl 两种后缀均实际产出相同的 JSON Lines,值、行数、顺序及 JSON null 均核对,3/3 轮通过。
    2. test_async_public_export 另外连续 3 轮、每轮 CSV/JSONL 两个异步导出分支,合计 6/6 通过;JSONL 的三行完整值和 CSV 头、三行内容均核对。

    Unhappy Path 覆盖

    1. 异步导出到不存在的目标目录,3/3 轮抛出 QueryError;随后源表 COUNT(*)=3,同一客户端仍能 SELECT 42,未把失败当成功,也未破坏数据或连接。

    白盒验证

    此问题是 Python SDK 生成导出 SQL 时缺少显式格式的产品接口缺陷,不涉及 Go 并发内部路径;Go -race 不适用。定向在线用例和 SDK 全部必跑 native contracts 已在对应的真实服务上运行。

    回归测试

    • 已有 SDK 定向在线回归 检查非 .jsonl 后缀的逐行 JSON 与完整值;同文件的异步导出测试覆盖错误路径。无需将 SDK 接口测试伪装为 MOTR 静态 SQL 测试,也未向 MO 或 MOTR 新提 PR。
    • 当前 main 的本地 SDK native contracts 完整运行结果为 70 passed,0 skipped;JUnit 与 provenance 留存在隔离工作树的 qa-night/sdk-contract-run2/。PR fix(python-sdk): unify query contracts and atomic manager operations #31262 的 CI 中 SDK 离线矩阵及 CI Required 通过;该 CI 的在线部分未运行,以上在线结果来自本地,不声称完整仓库 CI。

    测试证据

    • 修复 PR:#31262;离线 CI:run 40330391794。
    • 定向命令: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 不计入通过次数,设置后重跑如上。

    测试结论

    测试通过。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugneeds-triage

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions