fix(rls): 收斂 API DB access context
This commit is contained in:
@@ -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={
|
||||
|
||||
Reference in New Issue
Block a user