Summary
tests/test_database.py::test_agencies_table_logic intermittently fails in CI with:
> assert log["operation_type"] == OperationType.UPDATE.value
E AssertionError: assert 'INSERT' == 'UPDATE'
E - UPDATE
E + INSERT
tests/test_database.py:649
Observed in CI for PR #952 (unrelated JWT/OAuth change): https://github.com/Police-Data-Accessibility-Project/data-sources-app/actions/runs/24569030432/job/71836812437
Likely cause
The test does:
delete_change_log(db_client)
- Create agency (expects 1 INSERT log)
- Update agency name (expects 1 UPDATE log)
logs = db_client.get_change_logs_for_table(Relations.AGENCIES) — asserts len(logs) == 2 and logs[1] is the UPDATE
The length assertion passes (2 logs present), but logs[1] is the INSERT rather than the UPDATE. This suggests get_change_logs_for_table does not return rows in a deterministic order — when the INSERT and UPDATE have identical or near-identical created_at timestamps, their relative order is undefined.
Suggested fix
Either:
- Add a deterministic
ORDER BY (e.g., created_at ASC, id ASC) in get_change_logs_for_table, or
- Have the test look up the log by
operation_type rather than list index.
Repro
Re-run CI on any PR; surfaces intermittently. Not caused by the changes in #952.
Summary
tests/test_database.py::test_agencies_table_logicintermittently fails in CI with:Observed in CI for PR #952 (unrelated JWT/OAuth change): https://github.com/Police-Data-Accessibility-Project/data-sources-app/actions/runs/24569030432/job/71836812437
Likely cause
The test does:
delete_change_log(db_client)logs = db_client.get_change_logs_for_table(Relations.AGENCIES)— assertslen(logs) == 2andlogs[1]is the UPDATEThe length assertion passes (2 logs present), but
logs[1]is the INSERT rather than the UPDATE. This suggestsget_change_logs_for_tabledoes not return rows in a deterministic order — when the INSERT and UPDATE have identical or near-identicalcreated_attimestamps, their relative order is undefined.Suggested fix
Either:
ORDER BY(e.g.,created_at ASC, id ASC) inget_change_logs_for_table, oroperation_typerather than list index.Repro
Re-run CI on any PR; surfaces intermittently. Not caused by the changes in #952.