test(plex)+cleanup(quota): S2 code-review fixes (R6 S2)
/code-review high on S2 — 4 findings, 2 fixed, 2 no-change: - test_plex_sync_txn: a faked PlexClient fails on the second library; asserts the first library's row survives (per-section commit). Mutation-checked — moving the commit back out of the loop turns it red ([] == ['1']). - dropped the `[[quota-owns-its-session]]` memory slugs from quota.py docstrings (a dangling private-note reference in shipped code; the reasoning is already inline). No change: record_usage's per-call second connection is a transient spike, fine for this app's concurrency; the two-site `with SessionLocal()` duplication isn't worth a helper until a third caller appears. Gate: ruff clean; DB lane 181 green.
This commit is contained in:
@@ -126,7 +126,7 @@ def log_action(user_id: int, action: str) -> None:
|
||||
|
||||
Writes in its OWN session (like record_usage) — quota accounting is durable independent of the
|
||||
caller's transaction and must never commit the caller's session (that would flush a job's
|
||||
partial state mid-run, defeating its own rollback). See [[quota-owns-its-session]]."""
|
||||
partial state mid-run, defeating its own rollback)."""
|
||||
with SessionLocal() as qs:
|
||||
qs.add(QuotaEvent(user_id=user_id, action=action, units=0))
|
||||
qs.commit()
|
||||
@@ -158,7 +158,7 @@ def record_usage(units: int) -> None:
|
||||
back (or is read-only and never commits) must NOT lose the record — under-counting the shared
|
||||
daily budget risks overspending the real API quota. Equally, quota must never commit the
|
||||
CALLER's session (the old behaviour) — that persisted a job's partial state mid-run behind its
|
||||
own `except: db.rollback()`. See [[quota-owns-its-session]]."""
|
||||
own `except: db.rollback()`."""
|
||||
if units <= 0:
|
||||
return
|
||||
day = pacific_today()
|
||||
|
||||
Reference in New Issue
Block a user