add rowcount check

This commit is contained in:
Yansong Zhang 2026-01-08 11:08:34 +08:00
parent 75ccba6e52
commit 71bd20cf73
1 changed files with 1 additions and 5 deletions

View File

@ -61,12 +61,8 @@ class CreditPoolService:
TenantCreditPool.quota_used + credits_required <= TenantCreditPool.quota_limit,
]
stmt = update(TenantCreditPool).where(*where_conditions).values(**update_values)
result: CursorResult = session.execute(stmt)
session.execute(stmt)
session.commit()
if result.rowcount == 0:
raise QuotaExceededError(
f"Insufficient credits. Required: {credits_required}, Available: {pool.remaining_credits}"
)
except Exception:
logger.exception("Failed to deduct credits for tenant %s", tenant_id)
raise QuotaExceededError("Failed to deduct credits")