fix(backend): validate Display start_at must not exceed expires_at in Announcement ($25 bounty proposal)
Closed
AI
8h ago+62+62+01234567890123456789-1-1-0123456789
Description
Validates that Display in backend/models/announcement.py enforces start_at <= expires_at.
Currently, Display normalizes start_at and expires_at to UTC but lacks bounds validation. If start_at is after expires_at, an inverted display window is accepted, which causes temporal schedule anomalies. Furthermore, Announcement.from_dict uses _optional_submodel(Display, display_data) to guard against malformed display configurations; with bounds validation in place, documents with inverted display timestamps are safely caught as ValidationError and dropped rather than causing schedule corruption.
This change:
- Adds a
model_validatortoDisplayto ensurestart_at <= expires_atwhen both timestamps are specified. - Adds unit tests in
backend/tests/unit/test_announcement_display_bounds.pycovering valid bounds, equal timestamps, one-sided bounds,ValidationErroron inverted dates, and graceful sub-document dropping inAnnouncement.from_dict.
Test Plan
- Run unit tests:
Result: 5/5 tests passed in 0.008s.PYTHONPATH=backend python3 backend/tests/unit/test_announcement_display_bounds.py