[Arch] Multi-step database writes are not transactional #57
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
Severity: High | Category: Data
db.get_db()wraps a single connection only;upsert_shipment→add_event→finalize_shipmenteach open/commit their own connection independently. A crash mid-sequence leaves a shipment without its event.Recommendation: Add a
db.transaction()context manager threading one connection through the call sequence; use it iningest.py:353-374and bothscheduler.pyscrape-result paths.Refactoring safety: Add a test that forces a mid-sequence exception and asserts neither write persisted.
Full detail:
docs/architecture-review.md§ C + § H.7Fixed on branch
architecture-rework, commit519f712: addeddb.transaction()(explicitBEGIN IMMEDIATE/COMMIT/ROLLBACK) and threaded an optionalconn=parameter throughget_shipment/find_shipment/create_shipment/update_shipment/upsert_shipment/add_event.ingest.py's email pipeline now wrapsupsert_shipment+add_event(incl. the activities-loop events) in one transaction.Added
test_upsert_and_event_write_is_atomic_on_failure(forcesdb.add_eventto raise mid-sequence, asserts the shipment write rolled back too) — confirmed it fails on the pre-fix code by temporarily reverting, then passes after. Full suite: 240 passed at the time of this commit.