refactor(backend): select() and an inline now everywhere, held by a test
CLAUDE.md's canonical table names SQLAlchemy 2.0 select() and an inline datetime.now(timezone.utc), and both had drifted: five db.query(...) calls remained in routes/auth.py and routes/me.py (seven before the demo went), and four private now helpers stood in sync/videos.py, utils.py (imported as _now by explore and maintenance), scheduler.py (_now_iso) and the e2e seed. All are the canonical form now. Ruff cannot ban a method call on an instance or a function by name, so tests/test_canonical_patterns.py reads every app module's AST and fails on a .query(...) call or a now/_now/now_utc helper — seen red on a planted file.
This commit is contained in:
@@ -20,7 +20,7 @@ Quota: phase 1 costs ~(flagged / 50) units, phase 2 ~(batch / 50). Both respect
|
||||
backfill reserve as the other jobs so interactive syncs never starve.
|
||||
"""
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
from sqlalchemy import or_, select
|
||||
from sqlalchemy.orm import Session
|
||||
@@ -31,7 +31,6 @@ from app.models import Playlist, PlaylistItem, Video
|
||||
from app.notifications import create_notification
|
||||
from app.sync.runner import get_service_user
|
||||
from app.sync.videos import apply_video_details, parse_dt
|
||||
from app.utils import now_utc as _now
|
||||
from app.youtube.client import YouTubeClient
|
||||
|
||||
log = logs.get_logger(__name__)
|
||||
@@ -60,7 +59,7 @@ def _is_abandoned_upcoming(item: dict) -> bool:
|
||||
scheduled = parse_dt(live.get("scheduledStartTime"))
|
||||
if scheduled is None:
|
||||
return False
|
||||
return _now() - scheduled > timedelta(days=2)
|
||||
return datetime.now(timezone.utc) - scheduled > timedelta(days=2)
|
||||
|
||||
|
||||
def _evaluate(video: Video, item: dict | None) -> str | None:
|
||||
@@ -225,7 +224,7 @@ def run_maintenance(db: Session) -> dict:
|
||||
return {"reason": "no service user"}
|
||||
# One `now` for the whole run: each phase taking its own let a video phase 1 had just recovered
|
||||
# (stamped with phase 1's) pass phase 2's "not checked this run" test and be fetched twice.
|
||||
now = _now()
|
||||
now = datetime.now(timezone.utc)
|
||||
with YouTubeClient(db, user) as yt:
|
||||
phase1 = _recheck_flagged(db, yt, now)
|
||||
phase2 = (
|
||||
|
||||
Reference in New Issue
Block a user