You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Skip campaign events with unrepresentable times on the contact timeline - #7130
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
None yet
1 participant
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-01with a negative offset), that arithmetic raisesOverflowErrorand 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_eventscatchesOverflowErrorfrom computing the event time (including delivery-hour snapping) and skips that event.test_timeline_inactive_and_missing_anchoradds an event anchored on a0001-01-01value with a -3 day offset and asserts it's omitted.Behavior
0001-01-01T00:00:00-06:36Test plan
temba.contacts.tests.test_contactcrudlpassescode_check.pypasses