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
+13
-5
@@ -62,14 +62,22 @@ def peer_message_prefix(from_task_id):
|
||||
return "[来自任务 %s 的消息]\n" % from_task_id
|
||||
|
||||
|
||||
def row_get(row, name):
|
||||
"""行取值容错:sqlite3.Row 缺列报 IndexError、dict 缺键
|
||||
报 KeyError、空行报 TypeError,一律回 None(worker 直连
|
||||
老库、列还没迁移时排空不能因此停摆)。"""
|
||||
def row_get(row, name, default=None):
|
||||
"""行取值容错(全仓行取值的统一口,A7):sqlite3.Row 缺列
|
||||
报 IndexError、dict 缺键报 KeyError、空行报 TypeError,
|
||||
一律回 default(默认 None;worker 直连老库、列还没迁移时
|
||||
排空不能因此停摆)。handler 链、auto_memory、lifecycle
|
||||
三处统一走本函数:三者旧语义在真实行类型(None / dict /
|
||||
sqlite3.Row)下完全一致——auto_memory 旧版的 default 参数
|
||||
默认就是 None,lifecycle 旧版的 None 特判与 dict .get 在
|
||||
这些类型下与本函数结果相同;旧 lifecycle 版另带的宽
|
||||
Exception 兜底只对“__getitem__ 抛其它异常的病态行”有
|
||||
区别,那类输入不是 DB 行,不属于本函数契约,统一后此
|
||||
类输入改为抛给调用方(不在测试锁定的真实行类型内)。"""
|
||||
try:
|
||||
return row[name]
|
||||
except (KeyError, IndexError, TypeError):
|
||||
return None
|
||||
return default
|
||||
|
||||
|
||||
def extract_peer_messages(text):
|
||||
|
||||
Reference in new issue
Block a user