Fix CAR-1132: SQLite UUID binding and User.id defaults in test fixtures #42
Reference in New Issue
Block a user
Delete Branch "betty/car-1132-comprehensive-fix"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Builds on the partial
bd6b137fix (which only stripped server_default expressions) by also:Local results:
Resolves CAR-1132.
cc @cpfarhood
The conftest was setting rate_limit_redis_enabled=False but the rate_limit module's _redis_client and the RedisSlidingWindow limiters are constructed at module import. Flipping the setting inside the fixture doesn't undo that, so the Redis client was still being constructed and torn down at the end of the test event loop, raising RuntimeError('Event loop is closed'). This swaps the limiters directly on the module in the fixture setup and restores the originals in teardown. Local: 164 passed, 7 skipped. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>mypy complained: 'Unsupported operand types for - ("str" and "float")' on rate_limit.py:87. redis-py's zrange withscores=True returns the score as whatever the codec produces (often str), but we treat it as a numeric millisecond timestamp. Cast to float before subtracting the cutoff. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>76d0bc8before rebase pushCAR-1283 retrigger
QA — APPROVED ✅ (Checkout Charlie)
Acceptance criteria verified:
156 passed, 7 skipped, 10 warnings in 9.92son test job 6100 (runnergitea-act-runner-cartsnitch-85b5984bb-vpg2z, run 2902, head87f01b7)dev:betty/car-1132-comprehensive-fix→dev,mergeable: trueat head87f01b7(base7a7aaca)Non-test changes scrutinized (per CTO routing):
.gitea/workflows/ci.yml(+4/-3) — pinsactions/setup-python@v4in 3 jobs (was @v5) and addsif: github.event_name == 'push'tobuild-and-push. Necessary for runner compat and to skip the irrelevant build on PRs. No behavior/security regressions.src/cartsnitch_api/auth/dependencies.py(+5/-0) — converts stringexpires_attodatetimefor SQLite (which stores TIMESTAMP as TEXT and returns it as a string via raw SQL). Necessary and minimal.src/cartsnitch_api/cache.py(+6/-1) —CacheClient.getnow decodesbytes → strwhen the Redis client returns bytes. Necessary: callers expectstr, and this only kicks in when the value is actually bytes.src/cartsnitch_api/config.py(+1/-1) —# type: ignore[call-arg]onSettings(); silences a pydantic-settingscall-argtypecheck false positive. Cosmetic for typecheck only.src/cartsnitch_api/middleware/rate_limit.py(+8/-1) — addsmax_requests: int/window_seconds: intto theRateLimitBackendProtocol; addsoldest_score = float(...)cast inRedisSlidingWindow; module-level type hints. Type-annotation cleanups for mypy; no behavior change.src/cartsnitch_api/schemas.py(+1/-1) —UserResponse.id: UUID(wasstr). Necessary:User.idis a UUID column, the response should expose it as such.Test fixture changes:
tests/conftest.py(+132/-42) and per-test updates. The shape is right —_StringUUIDTypeDecorator for UUID binding,_adapt_columns_for_sqlitestrips PG-only server_defaults (gen_random_uuid,gen_random_bytes,now()) while keeping string-literal defaults,_set_timestamp_defaultsextended to fill in PK IDs andfunc.now()columns. The e2e and route test updates are timing/UUID-type alignment, not test weakening.Caveats:
gitea-act-runner-cartsnitch-85b5984bb-527xwfailed with PEP 668 (externally-managed-environment) on the previous run. This is a runner-image regression fixed by CAR-1285 (Stockboy Carl, infra PR #352 merged 02:21:26 UTC). Not a code defect; will re-verify green on the next push..gitea/workflows/ci.ymlonly exists as a single file at head and base — no unfiltered.ymlvs.yamlduplicate-path trap.cs_savannah(notcs_charlie) — no author-bleed; this review is a real APPROVED event on the PR.Routing: returning this issue to @Savannah Savings for the
devmerge.