code-to10 v6 A7: unify row_get on peer_messages
- peer_messages.row_get gains default=None (was None-only); the three old variants agree on all real row types (None / dict / sqlite3.Row): auto_memory's old default was already None, and lifecycle's old None special-case and dict .get give identical results on those types, so no call-site behavior changes and no call site passes a non-None default. - auto_memory and lifecycle delete their private _row_get copies and import peer_messages.row_get as _row_get (precedent: server, worker, handler_project, handler_support already do this); peer_messages imports no cloud modules, so no import cycle. lifecycle's old broad-Exception catch differs only for pathological __getitem__ inputs, which are not DB rows and are out of contract; this is documented on row_get, not left as a second story. - Scope note: other modules' own row_get copies (approvals, automations, marker_tools, todos, wait_ops) are out of this item's stated scope and are untouched. - Also drops auto_memory's unused 'import os' (pre-existing F401), so touched files are ruff E,F clean. - Tests: cloud/tests/test_row_get_unified.py locks the identity (both aliases ARE row_get), the real-row-type matrix, the None-default fallback, and snapshot_to_dict via the unified path. (cherry picked from commit 1644a0b837bfefb13cdc3c93d87fc1b246026607)
This commit is contained in:
1 parent
c33bfd240e
commit
be2962525b
4 files changed
+116
-24
No files matched your search
@@ -53,12 +53,15 @@ cloud/migrations.py 的对齐说明;PG DDL 同步进
|
||||
cloud/db.py POSTGRES_SCHEMA 与 MIGRATION_TABLES。
|
||||
"""
|
||||
|
||||
import os
|
||||
import re
|
||||
import time
|
||||
|
||||
from cloud.db import connect as _db_connect
|
||||
from cloud.identity import IdentityStore
|
||||
# 行取值统一走 peer_messages.row_get(A7):本模块旧私有版与之
|
||||
# 同款语义(缺列/缺键/空行回 default,默认 None),调用处仍
|
||||
# 用 _row_get 别名,行为不变。
|
||||
from cloud.peer_messages import row_get as _row_get
|
||||
from cloud.quota import default_quota_usd_micros as _quota_default
|
||||
from cloud.quota import monthly_usage as _quota_monthly_usage
|
||||
from cloud.quota import quota_for_owner as _quota_for_owner
|
||||
@@ -152,13 +155,6 @@ def quota_remaining_percent(db_path, owner):
|
||||
conn.close()
|
||||
|
||||
|
||||
def _row_get(row, name, default=None):
|
||||
try:
|
||||
return row[name]
|
||||
except (KeyError, IndexError, TypeError):
|
||||
return default
|
||||
|
||||
|
||||
def _first_line(text, max_len=200):
|
||||
for line in (text or "").splitlines():
|
||||
line = " ".join(line.split())
|
||||
|
||||
Reference in new issue
Block a user