Skip to content

[Bug]: MatrixOneTypeCompiler is dead code — wrong attribute name wires nothing #31402

Closed

Description

@Ariznawlll

DRAFT 23 (SDK, 2026-10-27) — filing now

Title: [Bug]: MatrixOneTypeCompiler is never wired — dialect sets attribute "type_compiler" but SQLAlchemy expects "type_compiler_cls"

Description

The MatrixOne SQLAlchemy dialect's 600-line custom type compiler — the code implementing visit_VECTOR (vecf32/vecf64 DDL), DECIMAL scale handling, BIGINT, TIMESTAMP, and dozens of delegating visit_* methods — is dead code, because the wiring uses the wrong attribute name:

# dialect.py:596-597
MatrixOneDialect.statement_compiler = MatrixOneCompiler
MatrixOneDialect.type_compiler = MatrixOneTypeCompiler      # ← not a SQLAlchemy hook

Verified (pure python, at import time):

MySQLDialect.type_compiler_cls  → exists (the real hook)
MySQLDialect.type_compiler      → does NOT exist as a dialect hook
MatrixOneDialect.type_compiler_cls  → MySQLTypeCompiler     ← unchanged! custom class never attached
MatrixOneDialect.type_compiler      → MatrixOneTypeCompiler  (inert attribute)

Therefore every CREATE TABLE compiled through the dialect silently uses the stock MySQL type compiler, not the MatrixOne one. Consequences observed/derivable:

  1. Vector columns: visit_VECTOR never runs. Any type reaching the generic MySQL path renders via the default user-defined-type rendering instead of the intended vecf32(N) — vector DDL works only because VectorType.get_col_spec happens to also work through a coincidental path (UserDefinedType's default visit_user_defined_type uses … type-specific rendering); anything relying on the explicit visit_VECTOR branch (e.g. VECTOR without get_col_spec) doesn't.
  2. visit_BIGINT/visit_big_integer returning plain "BIGINT" (dropping MySQL UNSIGNED semantics) — intended MO-tailoring never applies.
  3. The whole 1.4-branch else-arm (SA_VERSION < (2,0)) plus its own duplicate class at :462 is dead twice over (2.0+ is always taken today).
  4. Diagnostic observation that on SQLAlchemy 2.1.6 a lengthless String() in CreateTable raises VARCHAR requires a length on dialect matrixone — the stock MySQL compiler path with the MO dialect name, confirming which compiler is really active.

A secondary twist: had the attribute name been correct, several of the overrides would themselves misfire — e.g. the duplicated visit_timestamp/visit_TIMESTAMP pairs (later def silently shadows earlier), visit_binary calling mysql_compiler.visit_BINARY (wrong method name → AttributeError if ever hit). The class was never exercised, so none of these were ever caught.

Reproduction

from matrixone.sqlalchemy_ext.dialect import MatrixOneDialect, MatrixOneTypeCompiler
print(MatrixOneDialect.type_compiler_cls)     # <class MySQLTypeCompiler> ← custom class absent
print(getattr(MatrixOneDialect, 'type_compiler', None))  # the class, attached to a no-op attribute

Any version; the wiring simply never worked.

Impact

  • The SDK advertises a MatrixOne dialect with tailored type compilation; users actually get stock MySQL type behavior with the MO name. Every type-on-the-edge (unsigned bigint, no-length VARCHAR, 2.x TIMESTAMP variants, vector edge cases) behaves per MySQL rules the SDK authors believed they had overridden.
  • Dead 600-line class invites confident-but-wrong future edits (as the duplicated visit methods show); the bug is invisible because nothing errors.
  • Same family as the dead-letter API findings from the python-sdk sweep (never-invoked guard rails), but this one sits on the primary DDL path.

Expected behavior

  1. Wire correctly: MatrixOneDialect.type_compiler_cls = MatrixOneTypeCompiler (SQLAlchemy's documented hook — Dialect.type_compiler_cls); either delete the inert type_compiler assignment or keep it only as a deprecation alias.
  2. Delete the SA 1.4 else-branch (SA 2.0+ only in supported range) or gate it on a live distro check.
  3. De-duplicate the shadowed visit_timestamp/visit_TIMESTAMP pairs, fix visit_binary's wrong delegate method (visit_BINARY doesn't exist on the type compiler — should be the right visitor or drop the override).
  4. Add the regression that would have caught all of this in one line: assert MatrixOneDialect.type_compiler_cls is MatrixOneTypeCompiler, plus a CreateTable compile test with a VectorType column asserting vecf32(N) ends up in the DDL.

Activity

  1. added
    kind/bug
    on Oct 27, 2026
  2. added this to the MO-202610 milestone on Oct 27, 2026
  3. added theissue type on Oct 27, 2026
  4. Ariznawlll commented on Oct 27, 2026

    @Ariznawlll
    CollaboratorAuthor

    Scope correction after re-checking current main (2026-10-27): the runtime path used by the SDK's own engine creation now applies the type compiler correctly (dialect.type_compiler_instance = compiler in the dialect install hook), so engine-created flows are NOT affected. The remaining defect is narrower: the module-level class assignments at the bottom of dialect.py still use MatrixOneDialect.type_compiler = MatrixOneTypeCompiler (SQLAlchemy's hook attribute is type_compiler_cls), so anyone instantiating MatrixOneDialect() directly (tests, third-party dialect registration) gets the stock MySQL type compiler. Downgrading severity per this note; happy either way — class-level fix is one line.

  5. added a commit that references this issue on Oct 30, 2026
    bbfe556
  6. XuPeng-SH commented on Oct 30, 2026

    @XuPeng-SH
    Contributor

    QA handoff for merged #31774 (main bbfe55669a1440424914d45a283a1d0e36f722fa): please verify the public SDK contract and failure/recovery controls for MatrixOneTypeCompiler is dead code — wrong attribute name wires nothing. This isolated QA run inspected the issue and source but did not run functional tests or a live MatrixOne service at this SHA because the existing resource guard left insufficient headroom. Author-reported PR validation is separate evidence, not a result of this QA run.

  7. Ariznawlll commented on Oct 30, 2026

    @Ariznawlll
    CollaboratorAuthor

    结论

    测试通过。直接实例化的 MatrixOneDialect 已使用 MatrixOneTypeCompiler,生成的向量类型 DDL 可在真实服务执行。

    关键证据

    • 官方 main@d39d8a40343ccd40bf665036388df7a40ee867f8;修复 PR fix(python): unify SDK query and analytics lifecycle contracts #31774 合并提交 bbfe55669a1440424914d45a283a1d0e36f722fa 在祖先链;实际二进制与 SDK 同完整 SHA。本地隔离 1 CN / 1 TN / 1 LogService,Python 3.12、SQLAlchemy 2.0.43。
    • 三个独立库中,类级 type_compiler_cls 与直接实例的 compiler 均为 MatrixOneTypeCompiler;生成 DDL 含 vecf32(3) 与 numeric(10,2) 并实际建表。写入 [1,2,3]、Decimal 12.34 和 NULL 后读回正确,列元数据为 vecf32(3)。
    • 错误维度向量写入被拒绝,原表仍两行;每轮测试库清理。SDK dialect 离线测试 59/59 通过;MOTR #295 新增用例定向 3/3 通过、0 skipped。

    待解决点

  8. Ariznawlll commented on Oct 30, 2026

    @Ariznawlll
    CollaboratorAuthor

    回归位置更正:#295 已关闭并汇总至 MOTR #298;本 issue 的定向用例已补入 #298,之前所述测试结果及未覆盖项不变。#298 尚未合入,完整 MOTR suite 未运行。

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