fix: BUG-06..11 — pool lock, rounding, tz, infer_city, rowcount, double commit #14
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/bugs-06-to-11"
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?
Summary
Third and final tranche of audit fixes — the LOW + COSMETIC batch. Independent of PR #12 and PR #13 (no overlapping lines).
_get_pool()had a TOCTOU race on cold start. Two threads racing through theNone-check could each instantiate aThreadedConnectionPool; the second assignment overwrote the first and leaked its checked-out connections. Addedthreading.Lockwith a double-checked-locking pattern.clean_intusedint(float(s))which truncates ("3.9" → 3). Switched toround(...). All current call sites pass intrinsically-integer fields so production behaviour is unchanged; rounding is a safer default for future float-valued integer fields. Unit test updated._infer_citymapped every Kenyan plate toNBO, silently misclassifying Coast vehicles. Now returnsNonefor K-series plates and logs a warning so operators can tag them explicitly. Uganda (UMA/UAG → KLA) is unchanged. Analytics views alreadyCOALESCE(...)NULLassigned_cityinto theunassignedbucket, so no dashboard panels break.clean_ts("2024-04-12")returned the date verbatim, which Postgres interprets as00:00 UTC = 03:00 EAT— three hours off the operator's intent. Date-only strings are now anchored to Africa/Nairobi midnight (T00:00:00+03:00). Inputs with a time component pass through unchanged. Unit test added.rowcountcounters inpoll_live_positionsandpoll_tripswere namedupserted/insertedbut accumulatedcur.rowcountfromON CONFLICT DO UPDATEstatements — always 1 regardless of insert vs. update. Renamed tolive_pos_affected/history_inserted/trips_affected, and routedtrips_affectedto therows_upsertedslot ofingestion_log(it was previously logged asrows_inserted).conn.commit()inside thewith get_conn()block of_update_token_cache— the context manager auto-commits on__exit__.Test plan
pytest tests/unit/test_clean_helpers.pypasses (covers BUG-07 + BUG-09 directly).ingestion_logrows forjimi.device.track.mileagestart populatingrows_upsertedinstead ofrows_inserted.python import_drivers_csv.pyand confirm K-series plates emit the new "Kenyan prefix is ambiguous" warning and resolve toassigned_city IS NULL.tracksolid.api_token_cachestill updates correctly (token cache write is the BUG-11 code path).cityfilter still works —unassignedshould now contain the Kenyan vehicles.🤖 Generated with Claude Code
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.