Change how we count notifications in redis#2871
Open
jzbahrai wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses a race condition in SES batch receipt processing that could double-count annual limit notification totals in Redis when seeding occurs during a batch update.
Changes:
- Moves the annual-limit “seed state” check to run once per service after the batch DB write, then passes that seed result into per-notification counting logic.
- Updates
update_annual_limit_and_bounce_rateto acceptdid_we_seedfrom the caller instead of re-checking per notification. - Adds tests to validate that seeding during a batch prevents per-notification increments and that the seed check is performed once per service.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
app/celery/process_ses_receipts_tasks.py |
Checks annual-limit seed state once per service after batch DB update and uses it to prevent double counting. |
tests/app/celery/test_process_ses_receipts_tasks.py |
Adds regression tests covering seeding vs incrementing behavior and ensuring one seed check per service. |
Comments suppressed due to low confidence (1)
app/celery/process_ses_receipts_tasks.py:235
- This log statement uses a double-quoted string literal inside an f-string expression (aws_response_dict["message"]). In Python this form raises a SyntaxError at import time; use single quotes for the key (aws_response_dict['message']) or assign the value to a variable before formatting.
if not is_success:
current_app.logger.info(f"{log_prefix} Delivery failed with error: {aws_response_dict["message"]}")
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+336
to
+341
| service_seed_states: Dict[str, bool] = {} | ||
| for _, notification, _ in receipts_with_notification_and_aws_response_dict: | ||
| sid = notification.service_id | ||
| if sid not in service_seed_states: | ||
| _, did_we_seed = get_annual_limit_notifications_v3(sid) | ||
| service_seed_states[sid] = did_we_seed |
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 free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 batch write pattern in process_ses_results:
Inside that function, get_annual_limit_notifications_v3() is called which checks if seeding has occurred
The race condition: