fix: MariaDB JSON path compat for name_member + FAM-Core API verified

- name_member(): replace MySQL-only JSON_REPLACE/JSON_CONTAINS with wildcard
  JSON paths (unsupported in MariaDB 10.11) with Python-side JSON parsing
- FAM-Core venv rebuilt with Python 3.10.20 on NAS
- All API endpoints tested: health, status, member list, unnamed, naming
- POST /api/member/name: 人物A successfully named to 张三
- PROGRESS.md updated with full test results and task completion
This commit is contained in:
ericwyuan
2026-08-19 23:48:35 +08:00
parent 66b499725d
commit c8cd2f2665
2 changed files with 60 additions and 24 deletions

View File

@@ -384,15 +384,33 @@ def name_member(abstract_label: str, real_name: str, named_by: str) -> Dict:
updated_details_count = cursor.rowcount
# 4. 批量回溯更新 monitor_events.entities_json
# MariaDB 10.11 不支持 MySQL 的 $[*] 通配符 JSON 路径,
# 改用 Python 层解析 + 逐行更新
cursor.execute(
"""UPDATE monitor_events
SET entities_json = JSON_REPLACE(
entities_json, '$[*].person', %s
)
WHERE JSON_CONTAINS(entities_json->'$[*].person', JSON_QUOTE(%s))""",
(real_name, abstract_label)
"SELECT event_id, entities_json FROM monitor_events WHERE entities_json LIKE %s",
(f'%{abstract_label}%',)
)
updated_events_count = cursor.rowcount
import json as _json
updated_events_count = 0
for eid, entities_raw in cursor.fetchall():
if not entities_raw:
continue
try:
entities = _json.loads(entities_raw) if isinstance(entities_raw, str) else entities_raw
except (ValueError, TypeError):
continue
changed = False
if isinstance(entities, list):
for ent in entities:
if isinstance(ent, dict) and ent.get('person') == abstract_label:
ent['person'] = real_name
changed = True
if changed:
cursor.execute(
"UPDATE monitor_events SET entities_json = %s WHERE event_id = %s",
(_json.dumps(entities, ensure_ascii=False), eid)
)
updated_events_count += 1
conn.commit()
return {