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

@@ -1933,14 +1933,14 @@ class DecisionManager:
try:
from src.core.feature_flags import aiops_flags as _p6_flags
if _p6_flags.is_sub_flag_enabled("AIOPS_P6_SELF_DEMOTION"):
from src.db.base import get_session_factory as _p6_sf
from src.db.base import get_db_context as _p6_db_context
from src.db.models import AiGovernanceEvent as _GovernanceEvent
from sqlalchemy import select as _p6_select, func as _p6_func
from datetime import timedelta as _p6_td
_now = __import__("src.utils.timezone", fromlist=["now_taipei"]).now_taipei()
async with _p6_sf()() as _p6_sess:
async with _p6_db_context() as _p6_sess:
# 過去 7 天有幾筆未解決的 slo_violation
_viol_7d_q = await _p6_sess.execute(
_p6_select(_p6_func.count()).where(
@@ -1980,8 +1980,8 @@ class DecisionManager:
)
# 記錄保守模式事件
try:
from src.db.base import get_session_factory as _p6_sf2
async with _p6_sf2()() as _s2:
from src.db.base import get_db_context as _p6_db_context2
async with _p6_db_context2() as _s2:
_s2.add(_GovernanceEvent(
event_type="conservative_mode",
details={
@@ -2021,8 +2021,8 @@ class DecisionManager:
_push_decision_to_telegram(incident, token.proposal_data)
)
try:
from src.db.base import get_session_factory as _p6_sf3
async with _p6_sf3()() as _s3:
from src.db.base import get_db_context as _p6_db_context3
async with _p6_db_context3() as _s3:
_s3.add(_GovernanceEvent(
event_type="self_demotion",
details={