Skip to content

Skip campaign events with unrepresentable times on the contact timeline - #7130

Merged
rowanseymour merged 1 commit into
mainfrom
rowan/timeline-date-overflow
Oct 21, 2026
Merged

rowanseymour merged 1 commit into
mainfrom
rowan/timeline-date-overflow

Conversation

@rowanseymour

Copy link
Copy Markdown
Member

Summary

The contact timeline computes each campaign event's time as the contact's anchor date plus the event offset. If the anchor date is at the edge of the representable range (e.g. a field set to 0001-01-01 with a negative offset), that arithmetic raises OverflowError and the whole timeline request 500s. Such events are now skipped, the same way events whose anchor field the contact lacks are.

Fixes TEXTIT-TEMBA-4F5

Changes

  • Contact._get_campaign_events catches OverflowError from computing the event time (including delivery-hour snapping) and skips that event.
  • test_timeline_inactive_and_missing_anchor adds an event anchored on a 0001-01-01 value with a -3 day offset and asserts it's omitted.

Behavior

Anchor value Offset Before After
0001-01-01T00:00:00-06:36 -3 days timeline returns 500 event omitted, rest of timeline shown

Test plan

  • temba.contacts.tests.test_contactcrudl passes
  • code_check.py passes

@claude

claude Bot commented Oct 21, 2026

Copy link
Copy Markdown

Review summary

The fix looks correct. Wrapping both the offset addition and the astimezone().replace() delivery-hour snapping in the try covers both ways this can overflow: anchor + offset going past datetime.min/max, and the timezone conversion pushing a near-boundary value out of range. Skipping the event matches how a missing anchor is already handled, and the rest of get_timeline only sorts, compares and isoformat()s the surviving when values, so nothing else downstream should overflow.

The test reproduces the reported case (0001-01-01 with a -3 day offset) and checks that the event is missing from both future and past. One optional addition: the delivery-hour/astimezone branch and the upper bound (e.g. 9999-12-31 with a positive offset) aren't tested. Neither is required to merge.

No security or performance concerns. LGTM.

@rowanseymour
rowanseymour merged commit 032baa5 into main Oct 21, 2026
5 checks passed
@rowanseymour
rowanseymour deleted the rowan/timeline-date-overflow branch October 21, 2026 20:40
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 21, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant