diff --git a/pbl_common/audit.py b/pbl_common/audit.py index cac9913..e834aeb 100644 --- a/pbl_common/audit.py +++ b/pbl_common/audit.py @@ -87,12 +87,13 @@ def build_audit_record(action, table=None, row_id=None, detail=None, ctx=None, tenant_id=None, actor_id=None, actor_type=None, trace_id=None, result='ok', created_at=None): """构造一条审计记录 dict(tenant_id 打头,不落库)。""" - tid = normalize_tenant(tenant_id if tenant_id is not None else _safe_tenant(ctx)) - if not tid: + raw_tid = tenant_id if tenant_id is not None else _safe_tenant(ctx) + if raw_tid is None or str(raw_tid).strip() == '': raise ParamInvalidError( code=PBL_E_TENANT_MISSING, message='审计写入缺少 tenant_id(审计同样强制租户打头)', detail={'action': action, 'table': table}) + tid = normalize_tenant(raw_tid) if ctx is None: try: ctx_obj = current_context(strict=False)