fix(rls): 收斂 API DB access context
All checks were successful
Code Review / ai-code-review (push) Successful in 21s
CD Pipeline / tests (push) Successful in 1m20s
CD Pipeline / build-and-deploy (push) Successful in 4m15s
CD Pipeline / post-deploy-checks (push) Successful in 1m58s

This commit is contained in:
Your Name
2026-05-12 19:55:13 +08:00
parent 33c0577e93
commit ff30c61c4c
16 changed files with 327 additions and 55 deletions

View File

@@ -39,7 +39,7 @@ from dataclasses import dataclass
import structlog
from sqlalchemy import func, select
from src.db.base import get_session_factory
from src.db.base import get_db_context
from src.db.models import AiGovernanceEvent, PlaybookRecord
from src.utils.timezone import now_taipei
@@ -115,7 +115,7 @@ class TrustDriftDetector:
TrustDistribution樣本不足時 drift_detected=False
"""
try:
async with get_session_factory()() as session:
async with get_db_context() as session:
# 只計算 approved 狀態的 Playbook
total_q = await session.execute(
select(func.count()).where(
@@ -215,7 +215,7 @@ class TrustDriftDetector:
async def save_drift_event(self, dist: TrustDistribution) -> None:
"""將信任度漂移事件寫入 ai_governance_events。"""
try:
async with get_session_factory()() as session:
async with get_db_context() as session:
event = AiGovernanceEvent(
event_type="trust_drift",
details={