Skip to content

[Bug]: _row_to_account maps SHOW ACCOUNTS columns positionally and reads the wrong fields #31394

Closed

Description

@Ariznawlll

DRAFT 17 (SDK, 2026-10-27) — to be filed

Title: [Bug]: _row_to_account parses SHOW ACCOUNTS with the wrong column layout — comment/suspended fields get foreign values

Description

BaseAccountManager._row_to_account (account.py:~215) maps SHOW ACCOUNTS rows positionally:

return Account(
    name=row[0],
    admin_name=row[1],
    created_time=row[2],
    status=row[3],
    comment=row[4],               # ← actually suspended_time
    suspended_time=row[5],        # ← actually db_count
    suspended_reason=row[6],      # ← actually tbl_count
)

Actual SHOW ACCOUNTS output on current MatrixOne (verified against a live main build on 2026-10-26 during separate work; 10 columns today):

account_name | admin_name | created_time | status | suspended_time | db_count | tbl_count | size | snapshot_size | comments

Positional consequences:

SDK field receives
comment suspended_time (a timestamp — or NULL for open accounts)
suspended_time db_count (an integer!)
suspended_reason tbl_count (an integer!)

and the real comments column (position 9) is never read — user-visible account comments written via create_account(..., comment=...)/ALTER ACCOUNT COMMENT never round-trip through client.account.* reads. The Suspended_reason field the mapper expects isn't emitted by SHOW ACCOUNTS at all, so the model's field cannot be populated even in principle from this query.

Evidence path: Account objects built by get_account()/list_accounts()/create_account() (which re-reads via get) show comment=None for accounts that have comments (holding NULL/suspended_time instead), suspended_time=<int> type-nonsense, etc. Any app branching on status-adjacent suspended metadata or displaying comments gets wrong/garbage values silently.

Reproduction

client.account.create_account("acme", "admin", "pw", comment="ACME tenant")
acc = client.account.get_account("acme")
print(acc.comment)          # None (not "ACME tenant") — real comment lives in row[9], unread
print(acc.suspended_reason) # <tbl_count int> / None — column never existed

Cross-check on any server: SHOW ACCOUNTS; headers vs. the positional claims above.

Impact

  • The Account model's comment/suspended metadata surface is useless; quarantine/suspend ops UIs reading suspended_reason see integers; commenting on accounts (exists server-side and via the SDK's own create/alter APIs!) silently disappears on read — the write side works, the read side lies.
  • Silent type nonsense (timestamps in comment slots) also violates the dataclass type hints, waiting to crash whatever consumes them with format assumptions.
  • Any future server column additions/reshuffles will shift the misalignment again; positional parsing without name-based lookup is the structural cause.

Expected behavior

  1. Parse by column name (SHOW ACCOUNTS result metadata), not position — resilient to the server's column evolution (the SDK already consumes SQLAlchemy results elsewhere with .mapping support; SHOW results likewise carry names).
  2. Fix the mapping to the real layout (comments at end; drop the never-populated suspended_reason or source it from wherever it actually exists, e.g. mo_account catalog query if SHOW doesn't expose it).
  3. Regression: create an account with a comment, suspend it, then assert get_account().comment and suspended_time read back correctly typed.

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. XuPeng-SH commented on Oct 28, 2026

    @XuPeng-SH
    Contributor

    QA on merged SDK da0c931aa7a230d51c866057d6cd302d4b83d3f8 (#31527): tests/offline/test_account.py passed 39 tests, including current ten-column SHOW ACCOUNTS fixtures and sync/async account operations. This verifies the fixed current-layout mapping offline; no live account was created or suspended.

    The original acceptance explicitly asks for column-name-based parsing resilient to reordered columns. The merged helper still reads positional tuples, so that requirement is not established by these tests. Live create/comment/suspend/readback also remains unverified here. Handing off to QA to verify the original contract.

  5. Ariznawlll commented on Oct 28, 2026

    @Ariznawlll
    CollaboratorAuthor

    结论

    测试不通过。当前服务的原始列布局已修复,但 issue 明确要求的按列名解析及列顺序变化时的正确映射仍未满足。

    关键证据

    • 版本:官方 main@72d99c85751dc5b9b7775cb50571e7efd6400487,包含已合入修复 fix(python-sdk): map SHOW ACCOUNTS columns by the server layout #31527;macOS arm64,隔离单进程 LogService / TN / CN,SDK 和实际服务来自同一源码,服务 git_version() 为 72d99c8575。
    • 当前服务真实路径:创建独立账户并写入评论、暂停后分别通过 SDK 读取评论与暂停时间,3/3 均正确;每轮已删除测试账户。现有账户离线测试与 Stage 离线测试连续 3 轮,每轮 80 项通过。
    • 原 issue 的预期第 1 项要求按列名而非位置解析。用 SQLite/SQLAlchemy 真实结果对象模拟 SHOW ACCOUNTS 列名和值保持不变、仅将 comments 与 suspended_time 的位置互换,并包装为 SDK ResultSet(columns, rows) 后调用实际 AccountManager.get_account():3/3 轮中预期评论 expected comment,实际得到 suspended timestamp;预期暂停时间 suspended timestamp,实际得到 expected comment。这是模拟未来服务列顺序变化的契约测试,不是声称当前服务实际输出了重排的列。
    • 官方 main 随后前进到 9e29011e7313a57962adc00963baa659d1e81e37,在该 SHA 的 SDK 源码上重复上述模拟 3/3,字段仍然互换;真实服务账户读回的 3/3 仍对应此前 72d99c…。
    • 修复 PR #31527 的实现说明明确使用当前固定下标 4 和 9;get_account 仍通过 row[0] 查找账户,因而未利用结果的列名。现有测试只覆盖当前布局,无法证明列位置变化后的要求。

    待解决点

    • 请确认并实现 issue 所要求的按列名映射(包括按账户名查找的路径),补充重排列、缺失/新增列和 sync/async 公共 API 的回归;若该向前兼容要求需要调整,请先明确产品契约。
  6. gouhongshen commented on Oct 28, 2026

    @gouhongshen
    Contributor

    Existing-fix audit

    Assessment: partially fixed

    Fixed evidence

    Merged PR #31527, commit f7e89bc, corrects comments to index 9, suspended_time to index 4, and suspended_reason to None through a shared sync/async helper. Proof artifact: clients/python/tests/offline/test_account.py::TestAccountManager::test_get_account_maps_show_accounts_columns_by_layout. Subsequent QA reports successful live comment/suspension readback: #31394 (comment).

    Remaining problems

    1. Python SDK account decoding and account-name lookup still depend on column positions instead of result metadata. Reordering SHOW ACCOUNTS columns can swap comment/suspended_time or break account lookup; sync/async public APIs need column-name contract coverage. This is a self-contained SDK follow-up outside the permitted handler scope.
  7. gouhongshen commented on Oct 28, 2026

    @gouhongshen
    Contributor

    Split follow-up for the un-fixed portion: #31603.

  8. added 3 commits that reference this issue on Oct 30, 2026
    bbfe556
    43c6d84
    91dfab2
  9. XuPeng-SH commented on Oct 30, 2026

    @XuPeng-SH
    Contributor

    新修复转 QA:#31889 已合入 main,合并提交 91dfab2132c4c4fcd3f9a115dbfa968b196b8b14。

    完整评论所指按列名解析follow-up #31603 已由当前main共享SHOW ACCOUNTS mapper及get/list账户名查找实现;#31889在已有#31802路径上新增缺失/新增/大小写/重复列合同测试,没有第二套mapper。

    已核对 issue 正文、完整评论及当前合并源码/测试内容。历史失败按其原 SHA 保留;新修复直接覆盖上述残留,未发现适用于新修复的已验证反例或尚未完成的开发 follow-up。本轮仅源码/测试内容静态核对,没有运行 MatrixOne 服务或 SDK 回归;作者在 PR 内的运行结果是作者证据,不是本轮独立测试。转 Ariznawlll 继续验证,不代表验收通过。

    QA 待验范围:sync/async get/list与create/comment/suspend真实读回、重排列、缺失可选/新增/重复/缺失必需列及账户名查找。

  10. Ariznawlll commented on Oct 31, 2026

    @Ariznawlll
    CollaboratorAuthor

    结论

    测试通过。

    关键证据

    • 2026-10-31 本地隔离双 CN、TN、LogService,服务及 SDK 源码均为官方 main@4f894474ad10e1b9dc338868145a118a71c1fa23,修复 fix(python-sdk): unify SQL, transaction and driver boundaries #31889 在祖先链。
    • 每轮创建独立账户,验证初始 comment、修改 comment、暂停后 comment 和 suspended_time,再通过同步及异步 get/list 读取均正确,3/3;每轮删除测试账户。
    • SDK tests/offline/test_account.py 完整重复三轮共 81 passed;包含模拟 SHOW ACCOUNTS 重排列、大小写、缺失可选列、新增列、重复列、缺失必需列以及同步/异步账户名查找与用户归属。重排为模拟结果,不代表服务实际改变了列顺序。
    • 真实账户操作回归补充到 MOTR #298 的 issue_31394_31603_account_mapping.py(提交 0fc4ca2a),需显式启用 SDK 测试;该 PR 尚未合入,完整 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