Skip to content

Fix approved admin alerts getting stuck as broadcasting in production - #404

Open
soroush5 wants to merge 1 commit into
alphagov:mainfrom
soroush5:fix/approve-admin-areas-zendesk-keyerror
Open

Fix approved admin alerts getting stuck as broadcasting in production#404
soroush5 wants to merge 1 commit into
alphagov:mainfrom
soroush5:fix/approve-admin-areas-zendesk-keyerror

Conversation

@soroush5

@soroush5 soroush5 commented Sep 9, 2026

Copy link
Copy Markdown

Approving an admin-created alert in production crashed with KeyError: 'names' after the status had already been saved as broadcasting — so the alert looked broadcast but _create_broadcast_event never ran and nothing was ever sent. Retrying is impossible (broadcasting → broadcasting is not an allowed transition), so the alert was silently lost.

Root cause: _create_p1_zendesk_alert assumed areas["names"], but admin-created alerts store areas as {"ids": [...], "simple_polygons": [...]} — only API-created alerts have "names". The zendesk step runs after dao_save_object and before _create_broadcast_event, and only in production (is_prod), which is why no test ever caught it.

This accepts both shapes in the ticket text, and also makes the empty-areas validation use .get() so migrated {} rows get a clean 400 instead of KeyError: 'simple_polygons' (500).

Testing

  • 2 new regression tests in tests/app/broadcast_message/test_utils.py (admin-shaped approve on prod, empty-areas 400). Full pytest needs a live postgres plus the shared utils package, unavailable here — verified the fix by executing the real module path and by py_compile; flake8/black/isort clean.

_create_p1_zendesk_alert assumed areas['names'], but admin-created
alerts store areas as {'ids': [...], 'simple_polygons': [...]}, so
approving one in prod raised KeyError AFTER the BROADCASTING status
was saved but BEFORE the broadcast event/task was created - the
alert was stuck as broadcasting and never sent, with retry blocked.

Also make the empty-areas approval check tolerate a missing
'simple_polygons' key (clean 400 instead of KeyError 500).
@soroush5
soroush5 force-pushed the fix/approve-admin-areas-zendesk-keyerror branch from 5dde5ca to c2d649a Compare September 9, 2026 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant