Skip to content

Conversation

@50-Course
Copy link
Member

@50-Course 50-Course commented Dec 27, 2025

When sending notifications to thousands of devices, a single unregistered token would raise an exception and stop the entire batch. The results dict (containing success/failure info for each device) was lost, making it impossible to track which notifications actually succeeded.

This forced developers into perpetual try/except blocks and prevented proper cleanup of invalid tokens.

Solution

  • Return BulkNotificationResult with both results and errors
  • Each error is a structured dict containing:
    • registration_id: The device token that failed
    • error_type: The specific error (e.g., "Unregistered", "BadDeviceToken")
    • error_message: Descriptive error message
    • timestamp: When the error was captured
  • Preserve existing behavior of marking inactive tokens
  • No exception raised - graceful degradation for partial failures

Closes #750 (part 2 of 2)

cc @valhallen13 @igor-wl @s4cha

…in `apns_async`

When sending bulk APNS notifications, a single device failure would raise
an exception and disrupt the entire batch. This made it impossible to:
- Track which notifications succeeded vs failed
- Properly handle partial failures at scale
- Clean up only the failed registration IDs

Now `apns_send_bulk_message` returns `BulkNotificationResult` containing:
- `results`: dict mapping registration_id to success/failure status
- `errors`: list of error objects with registration_id, error_type,
  error_message, and timestamp
- `has_errors`: simple attribute to check if the batch operation raised
  an error and handle it properly in your code.

This allows graceful degradation where one bad token doesn't kill
thousands of successful notifications.

Refs #750
@codecov
Copy link

codecov bot commented Dec 27, 2025

Codecov Report

❌ Patch coverage is 15.38462% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.28%. Comparing base (b96739f) to head (10050b2).

Files with missing lines Patch % Lines
push_notifications/apns_async.py 15.38% 10 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #795      +/-   ##
==========================================
- Coverage   73.02%   64.28%   -8.75%     
==========================================
  Files          31       31              
  Lines        1294     1288       -6     
  Branches      215      215              
==========================================
- Hits          945      828     -117     
- Misses        301      415     +114     
+ Partials       48       45       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

issues with apns_async

1 participant