Skip to content

[Bug]: Python SDK silently creates signed BIGINT for mysql.BIGINT(unsigned=True) #31205

Closed

Description

@Ariznawlll

Description

The MatrixOne Python SDK's SQLAlchemy dialect silently compiles mysql.BIGINT(unsigned=True) as signed BIGINT. Tables created through the SDK therefore reject legal unsigned values above 2^63-1, although native MatrixOne SQL and MySQL accept them. The requested type and actual schema disagree without a DDL error.

Environment

  • MatrixOne main 5fe08a3307e246e1ab9951ab690b50557af0f509; isolated SQL service reports 8.0.30-MatrixOne-v1.3.0.
  • Python SDK 0.1.16 at that source revision; Python 3.11.14, SQLAlchemy 2.0.55, PyMySQL 1.2.3.
  • Independent control: MySQL 8.3.0.

Steps to Reproduce

import sqlalchemy as sa
from sqlalchemy.dialects import mysql
from matrixone import Client

client = Client(sql_log_mode="off")
client.connect(host="127.0.0.1", port=36601,
               database="qa_sdk_types_20261026", ssl_mode="disabled", on_connect=[])
table = sa.Table("sdk_unsigned_repro", sa.MetaData(),
                 sa.Column("id", sa.Integer, primary_key=True),
                 sa.Column("u", mysql.BIGINT(unsigned=True)))
print(sa.schema.CreateTable(table).compile(dialect=client._engine.dialect))
with client._engine.begin() as conn:
    table.create(conn)
client.execute("INSERT INTO sdk_unsigned_repro VALUES (1,9223372036854775808)")

Actual Behavior

  • SDK DDL prints u BIGINT; information_schema.columns.COLUMN_TYPE is bigint. Inserting 9223372036854775808 rejects with 1690 data out of range: data type int64.

Expected Behavior

  • Standard SQLAlchemy MySQL dialect prints u BIGINT UNSIGNED.
  • Native MatrixOne CREATE TABLE ... u BIGINT UNSIGNED has COLUMN_TYPE='bigint unsigned' and reads back 9223372036854775808 exactly. MySQL 8.3 preserves the same value.

Stability and Unhappy Path

  • 3/3 independent fresh SDK/native table pairs reproduce the metadata and boundary discrepancy.
  • A signed-range insert (id=2,u=7) succeeds in the SDK-created table. A duplicate-key insert (id=2,u=8) is rejected without modifying that row; subsequent SELECT 1 succeeds, and SDK pool checked-out count returns to zero.
  • The rejected 2^63 insert leaves the SDK-created table empty until the normal control insert. This is a schema-generation failure, not a failed-INSERT atomicity bug.

Evidence

Self-checking 3/3 probe with exact DDL, metadata, error, row and pool output: /private/tmp/mo-sdk-types-20261026/unsigned_bigint_3x.py. Search of MatrixOne open/closed issues for Python SDK unsigned and SQLAlchemy BIGINT UNSIGNED found no matching bug; mysql-compatibility-contract/README.md does not document a Python SDK unsigned limitation.

Code Analysis

clients/python/matrixone/sqlalchemy_ext/dialect.py:282-284 defines MatrixOneTypeCompiler.visit_BIGINT to return constant "BIGINT", ignoring type_.unsigned (SQLAlchemy 2.0 path). Do not infer DECIMAL UNSIGNED correctness from this case: native MO currently accepts negative values for that spelling in this isolated build, so this report is deliberately limited to BIGINT.

Regression

Add an SDK online test constructing mysql.BIGINT(unsigned=True), asserting generated DDL and COLUMN_TYPE='bigint unsigned', then inserting/reading 9223372036854775808 exactly. Include signed BIGINT as a negative-range control and a failed duplicate write followed by connection reuse. Existing clients/python/tests/online/test_sqlalchemy_bool_reflection.py checks that reflection retains type.unsigned but does not assert that SDK-generated DDL preserves the unsigned modifier.

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_type_metadata_and_values: SQLAlchemy BIGINT(unsigned=True) DDL reported unsigned in information_schema and round-tripped 2**64-1 exactly. A rejected incomplete insert preserved the existing row; SELECT 1 succeeded afterward. This is focused live SDK DDL/value evidence.

  6. Ariznawlll commented on Oct 26, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:官方 main;完整 commit:59bad9e8aea4314af30fd25ce53267df5140c8fa。修复 PR #31262 已 MERGED,merge commit 28e8760905a7f39dba2ce436357ea75492f30512 已核实在此 main 祖先链。
    • 部署方式:隔离 macOS arm64 本地 1 LogService / 1 TN / 2 CN,当前 commit 重建 mo-service SHA-256 af1930d6b0fd6d387be01d55635a0ea5dc5f225440234ff942cddebb511078b2,SQL 端口 47011,git_version()=59bad9e8ae;Python 3.12、SQLAlchemy 2.0.55、PyMySQL 1.2.3。测试日期:2026-10-27。

    原问题验证

    3 个全新数据库分别用 SDK SQLAlchemy mysql.BIGINT(unsigned=True) 建表,并用原生 SQL BIGINT UNSIGNED 建对照表。两表 SHOW CREATE TABLE 均含 bigint unsigned,information_schema.columns.COLUMN_TYPE='bigint unsigned';插入/读回原失败边界 9223372036854775808(2^63)均为该精确整数,3/3。SDK 不再悄然创建 signed BIGINT。

    Happy Path 覆盖

    1. SDK 与原生表均另外读回无符号上界 18446744073709551615(2^64−1)及普通正数 7,值/类型一致,3/3。
    2. 已合入 SDK 在线类型合同 test_type_metadata_and_values 独立重跑 3/3;当前 main 的 SDK 在线质量合同文件 17 项通过(SQLAlchemy 2.0.55;2.1.6 也 17 项通过)。

    Unhappy Path 覆盖

    1. 对两表已存在的 id=2 再次插入,3/3 均返回 1062;原三行的 2^63、2^64−1、7 未改变,随后 SELECT 1 正常。
    2. 每轮断开连接、删除独立库并核对不存在;在线合同核对连接池借出数归零。

    白盒验证

    本问题属于 SDK 生成 SQL DDL 的公开客户端路径,并非 Go 内部竞态;未运行 Go UT/race。通过实际 DDL、元数据和两个越过 signed 上界的读回值交叉验证。

    回归测试

    复用已合入 PR #31262 的 SDK 在线 test_type_metadata_and_values。本轮未新增 MO PR 或 MOTR #278 用例:纯 SQL 无法证明 SDK 是否保留 unsigned=True。PR 的 Python SDK offline 6 个矩阵任务及 CI Required 成功;online CI 被路由跳过,已在隔离服务补测。未运行完整 MatrixOne BVT/MOTR/CI。

    测试证据

    • 本地可复跑对照脚本:/private/tmp/mo-six-qa-20261026/qa-night/probe_31203_31205.py,3/3 输出含两种边界整数、bigint unsigned、1062 和 CLEANED。
    • 已合入在线回归;PR CI。

    测试结论

    测试通过。

  7. Ariznawlll commented on Oct 29, 2026

    @Ariznawlll
    CollaboratorAuthor

    结论

    测试不通过。原 issue 的 SQLAlchemy unsigned 之外,简化 Client.create_table(..., {'v':'bigint unsigned'}) 仍创建 signed BIGINT,建议同一修复验收一并覆盖此入口,不另提重复 issue。

    关键证据

    • 官方 main@c6683bd2f531dcaa80e153c0924dac619c49dc9d,SDK 同提交;本地隔离 1 LogService / 1 TN / 1 CN,git_version()=c6683bd2f5。
    • 三个独立新库,以下声明均成功,但 information_schema.columns.COLUMN_TYPE 为 bigint,插入 9223372036854775808 报1690 data type int64,表仍为空:
    client.create_table('requested_uint', {'id':'int','v':'bigint unsigned'}, primary_key='id')
    client.execute('INSERT INTO requested_uint VALUES(1,9223372036854775808)')
    • 同库原生 CREATE TABLE native_uint(id INT PRIMARY KEY,v BIGINT UNSIGNED) 正常插入并精确读回 9223372036854775808;错误后 SELECT 1 正常。3/3。
    • Client.create_table() 把 'bigint' 与 'bigint unsigned' 合并调用 add_bigint_column(),后者构造不带 unsigned 的 BigInteger。这次不是先前 dialect visit_BIGINT 的同一函数,但属于原报告中声明 unsigned 未保留的同一用户可见验收边界。

    待解决点

    • 在原类型修复回归中加入简化字符串定义入口,比较 DDL、unsigned metadata、2^63 边界和拒绝后的完整行集;本次没有重新打开 issue 或修改标签。
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