diff --git a/apps/api/src/services/awooop_truth_chain_service.py b/apps/api/src/services/awooop_truth_chain_service.py index aac080349..8a6db6cb1 100644 --- a/apps/api/src/services/awooop_truth_chain_service.py +++ b/apps/api/src/services/awooop_truth_chain_service.py @@ -158,6 +158,13 @@ def _inbound_lookup_branch_limit(limit: int) -> int: return max(1, min(int(limit), _INBOUND_LOOKUP_BRANCH_LIMIT)) +def _outbound_database_cutoff(value: datetime) -> datetime: + """Match the production outbound table's naive-UTC timestamp contract.""" + if value.tzinfo is None: + return value + return value.astimezone(UTC).replace(tzinfo=None) + + async def _fetch_inbound_conversation_event_rows( db: Any, *, @@ -440,7 +447,7 @@ async def _fetch_outbound_rows_for_incidents( "incident_ids": source_ids, } if cutoff is not None: - base_params["cutoff"] = cutoff + base_params["cutoff"] = _outbound_database_cutoff(cutoff) async def fetch_branch( where_sql: str, params: dict[str, Any] | None = None diff --git a/apps/api/tests/test_awooop_truth_chain_service.py b/apps/api/tests/test_awooop_truth_chain_service.py index a89e694e6..846abedf1 100644 --- a/apps/api/tests/test_awooop_truth_chain_service.py +++ b/apps/api/tests/test_awooop_truth_chain_service.py @@ -233,6 +233,8 @@ async def test_batch_outbound_lookup_never_casts_full_envelope_to_text( assert all("source_envelope::text" not in sql for sql, _ in calls) assert all("FROM unnest" not in sql for sql, _ in calls) assert all("content_preview ILIKE" not in sql for sql, _ in calls) + assert all(params["cutoff"] == cutoff.replace(tzinfo=None) for _, params in calls) + assert all(params["cutoff"].tzinfo is None for _, params in calls) def test_ansible_audit_keeps_external_incident_id_in_json_not_bigint_column() -> None: