How a Timezone Bug Silently Corrupted Daily Sales Reports in Production
A software developer discovered that daily sales reports for stores in Lagos and London were consistently showing zero sales for the final two hours of each day due to a timezone handling bug. The root cause was that UTC midnight was used as the day boundary for all stores, incorrectly assigning late-night orders to the wrong calendar day for locations east of GMT. The bug only surfaced in production — not in development — because retried Celery tasks passed already timezone-aware datetime objects to a pytz localize() call that expects naive datetimes, triggering a ValueError. The fix involved adding a per-store IANA timezone field and a helper function that converts each store's local day boundaries into a UTC range before filtering orders. The author notes the underlying risk persists even in modern Django using zoneinfo, warning that passing aware datetimes into functions expecting local midnight bounds can silently return wrong data without proper input guards.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in