Skip to content

[Bug]: Python SDK documented legacy Query cannot execute for direct callers #31263

Closed

Description

@LeftHandCold

Is there an existing issue for the same bug?

  • I have checked open and closed issues.

Searched for Python SDK / ORM / legacy Query / Query.execute / _execute / AttributeError, and inspected related reports. #30960 concerns modern query count/first semantics and async build state; #31210 concerns string-table result construction; #31195 concerns DML ORDER BY/LIMIT preservation. None reports this documented legacy class's missing execution delegate or its model-name incompatibility. The corresponding _execute PR search also found no matching report/fix.

Branch Name

main

Commit ID

861a2c4cb68961d8b6b01f18e0aa6ac52a3a505f

Also reproduced on the previous frozen main 83c1e23526fc0ed31188abd7fc2ca87cd3a6d4b3 and the published PyPI matrixone-python-sdk==0.1.16 wheel, not only an editable source checkout.

Other Environment Information

  • Linux; Python 3.11.2.
  • Current-main reproduction with SQLAlchemy 1.4.54 and 2.0.55; published-wheel reproduction with 2.0.55.
  • The wheel was downloaded directly from https://pypi.org/simple, without modifying it: matrixone_python_sdk-0.1.16-py3-none-any.whl, SHA256 8a9b82bad22ce5940449614757c505f61c1a4b88a3df5e78137a3386566cb8d6.
  • No MatrixOne server is needed to reproduce these Python exceptions: they occur before calling Client.execute. Behavioral controls used a real SQLite in-memory executor attached at the public client execution boundary, with actual row-state assertions.

Actual Behavior

The publicly exported and documented legacy matrixone.orm.Query cannot execute when directly constructed:

  1. With an ordinary SQLAlchemy mapped model, the legacy SQL builders read model_class._table_name and raise AttributeError: type object 'Record' has no attribute '_table_name'. They do not resolve the standard __tablename__ despite the class documenting SQLAlchemy-model support.
  2. Supplying the legacy model-name alias allows SQL generation to complete, but every tested execution path then raises AttributeError: 'Query' object has no attribute '_execute'. Query does not define this method and inherits only from object. The method on the separate BaseMatrixOneQuery class cannot serve as its delegate.

This is an application-visible failure for callers importing and directly using Query. It is not a failure of the normal Client.query() factory, which returns MatrixOneQuery; that class inherits the valid execution delegate.

Observed results on current main and the published wheel:

Direct legacy operation, with the model-name alias supplied Result Backend calls
all() missing _execute AttributeError 0
first() same 0
count() same 0
SELECT execute() same 0
insert(...).execute() same 0
update(...).execute() same 0
delete() same 0

The synthetic table remains unchanged after every failing call. This report demonstrates a deterministic client API failure; it does not claim a production incident or data corruption.

Expected Behavior

The retained public Query(model, client) API should resolve its advertised model types and dispatch SQL through the supplied client. Labeling the class “legacy” and recommending a newer class does not make its documented constructor an abstract or unsupported API.

If retaining direct legacy construction is no longer intended, the supported API contract, exports, documentation and migration behavior need an explicit decision rather than an internal AttributeError during execution.

Steps to Reproduce

In a clean environment:

python -m pip install matrixone-python-sdk==0.1.16 SQLAlchemy==2.0.55

Run the following without a server. An unconnected real Client is sufficient because neither failure reaches connection validation or SQL dispatch:

from matrixone import Client
from matrixone.orm import Query
from sqlalchemy import Column, Integer, String
from sqlalchemy.orm import declarative_base

Base = declarative_base()

class Record(Base):
    __tablename__ = "sdk_legacy_records"
    id = Column(Integer, primary_key=True)
    value = Column(String(32))

client = Client()

def probe(label, action):
    try:
        action()
    except Exception as exc:
        print(label, type(exc).__name__, str(exc))

probe("normal mapped model", lambda: Query(Record, client).all())

# Supply only the table-name convention required by the legacy SQL builder.
# This does not monkeypatch Query or add its missing execution method.
Record._table_name = Record.__tablename__
probe("SELECT", lambda: Query(Record, client).all())
probe("UPDATE", lambda: Query(Record, client).filter("id = ?", 1)
      .update(value="updated").execute())
probe("DELETE", lambda: Query(Record, client).filter("id = ?", 1).delete())

Actual output:

normal mapped model AttributeError type object 'Record' has no attribute '_table_name'
SELECT AttributeError 'Query' object has no attribute '_execute'
UPDATE AttributeError 'Query' object has no attribute '_execute'
DELETE AttributeError 'Query' object has no attribute '_execute'

A connected client encounters the same attribute lookup before its execute method can run.

Additional information

Why this is a reachable API defect

Controls and test gap

  • Against the same in-memory table, Client.query(Record) read/update/delete controls dispatch and produce the expected results/row changes. The INSERT positive control uses raw Client.execute; the modern query class does not expose the legacy .insert() method, so the two builders should not be treated as interchangeable for every operation.
  • A diagnostic local subclass supplying only _execute -> self.client.execute makes all seven legacy operations dispatch successfully when the model-name alias is present. This isolates the missing delegate; it is not a product patch or a workaround that fixes ordinary model-name resolution.
  • Independently tested ordinary mapped models without that alias: five legacy read/DML cases fail on _table_name before dispatch, while the Client.query(model).all() control succeeds.
  • The existing test_query_update.py imports BaseMatrixOneQuery and MatrixOneQuery, not legacy Query. Its mocks therefore do not test direct legacy construction. No direct legacy Query(...) regression coverage was found in the current SDK tests/examples.

Regression coverage should instantiate the exported legacy class directly, cover standard mapped models as well as the legacy table-name convention, and observe the client's execution callback without injecting Query._execute into the object under test.

Customer workaround

Use client.query(Model) / MatrixOneQuery for supported read/update/delete operations. For insertion, use a supported client API such as Client.execute(...); do not assume the modern builder has legacy Query.insert().

Activity

  1. added
    severity/s0
    and removed on Oct 26, 2026
  2. added a commit that references this issue on Oct 26, 2026
    28e8760
  3. 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_legacy_query_native_execution and offline direct-legacy-query contracts. Direct Query(model, client) callers executed count, filter/first, all, and mapped physical-name/projection paths with exact row values; connection reuse succeeded.

  4. Ariznawlll commented on Oct 27, 2026

    @Ariznawlll
    Collaborator

    测试版本

    • 官方 main:420786e21566e5b9d5875e7d6a7f3102fd0761af;修复 PR fix(python-sdk): unify query contracts and atomic manager operations #31262 已 MERGED,merge commit 28e8760905a7f39dba2ce436357ea75492f30512 已核实在该 main 祖先链。
    • 隔离本地部署:该 SHA 重建的 1 LOG / 1 TN / 2 CN,SQL 47011/47012;Python 3.12、SQLAlchemy 2.0.55、同工作树 Python SDK;二进制 SHA-256 8bd0f1f4c60cd0590c68cdbb2cbca31fc9d39d071ec367ab56d5c49b4eec327e。
    • 测试日期:2026-10-27。

    原问题验证

    直接构造文档中的 Query(model, client) 而非只经 client.query():count() 为 3,filter(id=1).first().label='red';插入 id4、更新 v=9、读回、删除后 count 恢复 3。另用 Python 属性与物理列名不同的映射,按真实 id 查询得到 display=red。原先直接调用不能执行的路径连续 3 轮通过。

    Happy Path 覆盖

    1. select('label','id') 投影映射到 (display,key)=('red',1),确认列映射和返回值正确。
    2. 四个在线 SDK 合同文件连续 3 轮每轮 70/70 通过;112 个定向离线合同也连续 3 轮通过。两类测试零失败、错误、跳过。

    Unhappy Path 覆盖

    1. id4 删除后不存在且总数回到 3;没有把临时 DML 残留在表中。

    白盒验证

    核对已合入回归的 SDK 公开入口、SQL/返回值断言和修复后实际服务结果;未修改产品源码,未运行全量 SDK suite 或 race。

    回归测试

    #31262 已包含 clients/python/tests/online/test_sdk_quality_contracts.py::test_legacy_query_native_execution。Python SDK API 行为无法由纯 SQL MOTR 代替,未新增 MO 或 MOTR PR。#31262 六个离线 SDK CI job 成功;在线 CI SKIPPED,在线结果采用本地实测。

    测试证据

    本地 JUnit:/private/tmp/mo-six-qa-20261026/qa-night/sdk-contract-round-{1,2,3}.xml(每轮 tests=70、失败/错误/跳过均 0)及 sdk-offline-round-{1,2,3}.xml(每轮 112、失败/错误/跳过均 0)。修复 PR:#31262 。

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s0

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions