Skip to content

[Bug]: snapshot created_at parsed as naive local datetime; exists() maps every error to False #31405

Closed

Description

@Ariznawlll

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

Title: [Bug]: Snapshot timestamps parsed with local-timezone fromtimestamp (naive local datetime, off by UTC offset); exists() swallows all errors as "not exists"

Description

Two defects in the snapshot manager family (matrixone/snapshot.py):

1. _parse_snapshot_row renders snapshot times in the machine's local timezone

timestamp = datetime.fromtimestamp(row[1] / 1_000_000_000)   # naive LOCAL time

datetime.fromtimestamp(x) with no tz argument produces a timezone-naive datetime in the host's local timezone. The snapshot's creation instant (nanoseconds since epoch from the server) is thus displayed as whatever the SDK host's TZ happens to be — a user in UTC+8 sees timestamps 8 hours ahead of a user in UTC for the same snapshot, and neither value is labeled as naive-local. Snapshot.created_at flows into every list/get result and into REST/tooling output.

Correct forms: datetime.fromtimestamp(x, tz=timezone.utc) (aware UTC) — or at minimum aware-local — but an unaware local rendering is the one option that cannot be reasoned about by consumers.

2. exists() translates every error into "False"

def exists(self, name):
    try:
        self.get(name); return True
    except SnapshotError:
        return False

get() wraps any failure (connection error, permission error, SHOW SNAPSHOTS parse failure, transient server error) into SnapshotError. exists() therefore reports False for snapshots that do exist whenever anything else goes wrong. Callers branch on this weakly-typed boolean everywhere — including clone_database_with_snapshot/clone_table_with_snapshot which pre-flight check via snapshots.exists(...) and refuse valid operations, and restore_* paths. A transient blip turns into "snapshot does not exist", which misleads operators into re-creating snapshots or abandoning restores.

3. (family addendum) CREATE SNAPSHOT interpolates name/database/table raw

f"CREATE SNAPSHOT {name} FOR DATABASE {database}" — no escaping at all (not even the no-op helpers used elsewhere); one more member of the escaping family consolidated by today's other issues.

Reproduction

import datetime
# 1) timezone:
ts = datetime.datetime(2026, 10, 27, 5, 0, 0, tzinfo=datetime.timezone.utc).timestamp()
row_like = ts * 1e9
print(datetime.datetime.fromtimestamp(row_like / 1e9))    # local-time rendering — differs per host TZ
print(datetime.datetime.fromtimestamp(row_like / 1e9, tz=datetime.timezone.utc))  # the intent

# 2) exists(): with a dead/permission-limited connection the manager returns False

Impact

  • Timezone: every GUI/CLI consuming Snapshot.created_at shows drift by the host offset; cross-region teams see "snapshots created in the future/past". Silent, permanent, and the kind of thing that corrupts audit trails.
  • exists(): flaky infrastructure anywhere exists() gates operations — the class of false-negative that breaks restore automation and wastes on-call hours.

Expected behavior

  1. Parse with tz=timezone.utc (or return aware local with explicit tz attribute), and document the returned value; library-wide test hosts set different TZs (env TZ=) to lock behavior.
  2. exists() should distinguish SnapshotNotFound (a dedicated exception) from infra errors — infra errors must propagate (or be logged + raise), not masquerade as presence/absence.
  3. Escape snapshot/db/table names in CREATE (family fix).

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. added a commit that references this issue on Oct 30, 2026
    bbfe556
  5. XuPeng-SH commented on Oct 30, 2026

    @XuPeng-SH
    Contributor

    QA handoff for merged #31774 (main bbfe55669a1440424914d45a283a1d0e36f722fa): please verify the reported public SDK contract and its failure/recovery controls for snapshot created_at parsed as naive local datetime; exists() maps every error to False. This isolated QA run inspected the issue and merged PR but did not run tests or a live MatrixOne service at this SHA because the existing resource guard left insufficient headroom. The PR's author-reported validation is separate evidence, not a result of this QA run.

  6. Ariznawlll commented on Oct 30, 2026

    @Ariznawlll
    CollaboratorAuthor

    结论

    测试通过。快照时间按 UTC 返回,真实不存在的快照与连接异常被区分,同步和异步接口均符合预期。

    关键证据

    • 官方 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。
    • 三个独立库中实际创建数据库级快照,并将 SDK 读取的 created_at 与目录表纳秒时间戳独立换算的 UTC 值逐值比较;客户端进程分别设置 UTC、Asia/Shanghai、America/New_York 后,同步和异步读取仍为同一带 UTC 时区的时间。
    • 已存在快照的 exists 为 True,不存在的为 False;分别断开同步/异步客户端后调用 exists 均抛连接异常,未返回 False。含连字符的引用式快照名可创建、查询并删除;快照和测试库每轮清理。
    • 新增 MOTR #295 定向 3/3 通过、0 skipped;已有快照字符串回归在同版本 3/3 通过;SDK 快照离线测试 27/27 通过。

    待解决点

  7. 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