Repository navigation
Fix admin bulk result reporting across push providers - #830
Conversation
Signed-off-by: Emre K <110906681+kocaemre@users.noreply.github.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #830 +/- ##
==========================================
+ Coverage 74.65% 78.53% +3.88%
==========================================
Files 32 32
Lines 1365 1356 -9
Branches 226 220 -6
==========================================
+ Hits 1019 1065 +46
+ Misses 300 239 -61
- Partials 46 52 +6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| return {registration_ids[0]: status} | ||
|
|
||
| with mock.patch( | ||
| "push_notifications.apns_async.apns_send_bulk_message", side_effect=send_group |
There was a problem hiding this comment.
apns_async imports aioapns, which the 3.7–3.9 jobs don't have, so this test fails there. It needs a skip like the other APNS tests.
| with mock.patch("push_notifications.webpush.webpush_send_message", side_effect=send): | ||
| admin.send_messages(HttpRequest(), WebPushDevice.objects.order_by("id"), bulk=True) | ||
|
|
||
| self.assertEqual(admin.message_user.call_args_list[0].kwargs["level"], messages.ERROR) |
There was a problem hiding this comment.
call_args.kwargs and .args are 3.8+, but CI still runs 3.7. call_args[1] and call_args[0] work everywhere (also lines 40, 53, 67, 68, 87 and 88).
| success = 0 | ||
| for batch in ret: | ||
| for response in batch: | ||
| # Some providers return a list per chunk. |
There was a problem hiding this comment.
Nothing returns nested lists here, and ret only ever has one item in bulk mode, so one loop is enough. The comment looks unnecessary too, so feel free to drop it.
Signed-off-by: Emre K <110906681+kocaemre@users.noreply.github.com>
|
Thanks for the review. Follow-up fe21fd4 uses Python 3.7-compatible mock call tuples, skips the aioapns-only regression on Python <3.10, and removes the unused nested response-list handling. Previous CI RED: Python 3.8/3.9 APNS test failed; local GREEN: |
Hey @kocaemre Using AI is fine, but please, review what it writes yourself before pushing or replying. If this keeps happening I'm not sure what we'd do about it, and honestly it makes me less keen to review these PRs. |
|
how did this pass review? that's a lot of crap out there in the description. |
@50-Course I agree, the description reads like unedited AI output. I've already asked the contributor to review what they submit. I reviewed the code, requested changes, and those were addressed. CI passed, and I didn't find any remaining issues, so I merged it. We'll probably see more PRs like this. We may need clearer guidelines and a way to deal with contributors who repeatedly ignore them. It might be worth looking at how other projects handle this, since I doubt we're the only ones facing this in the Django ecosystem. I'd be interested to hear your thoughts on this, @50-Course. |
Summary
Fix #829: the admin bulk action now inspects every provider response rather than only the first item. An inactive-only selection no longer raises
IndexError; WNS response strings and errors are reported instead of crashing; failures from later APNS groups and Web Push devices are no longer hidden. No provider send implementation changes. Existing single-send behavior and GCM admin action are retained.Verification
RED, each before its corresponding fix (
DJANGO_SETTINGS_MODULE=tests.settings):python -m pytest tests/test_admin.py::WebPushDeviceAdminTestCase::test_bulk_action_with_only_inactive_devices_does_not_crash_or_claim_success -q --no-cov -p no:cacheprovider --tb=short→ 1 failed,IndexError: list index out of range.python -m pytest tests/test_admin.py::WNSDeviceAdminTestCase::test_bulk_action_reports_string_responses_without_crashing -q --no-cov -p no:cacheprovider --tb=short→ 1 failed,AttributeError: 'str' object has no attribute 'items'.python -m pytest tests/test_admin.py::WNSDeviceAdminTestCase::test_bulk_action_reports_wns_failure -q --no-cov -p no:cacheprovider --tb=short→ 1 failed, uncaughtWNSNotificationResponseError: HTTP 410.python -m pytest tests/test_admin.py::APNSDeviceAdminTestCase::test_bulk_action_reports_failures_from_later_application_group -q --no-cov -p no:cacheprovider --tb=short→ 1 failed, missing error-level message (KeyError: 'level').python -m pytest tests/test_admin.py::WebPushDeviceAdminTestCase::test_bulk_action_reports_first_failed_webpush_with_later_success -q --no-cov -p no:cacheprovider --tb=short→ 1 failed,KeyError: 'success'.GREEN (Python 3.12, Django 5.2):
DJANGO_SETTINGS_MODULE=tests.settings PYTHONDONTWRITEBYTECODE=1 python -m pytest tests/test_admin.py -q --no-cov -p no:cacheprovider --tb=short→ 8 passed.python -m pytest tests/ -q --no-cov -p no:cacheprovider --tb=short→ 108 passed, 2 skipped, 45 subtests passed; one existing Web Push deprecation warning.DJANGO_SETTINGS_MODULE=tests.settings_unique python -m pytest tests/tst_unique.py -q --no-cov -p no:cacheprovider --tb=short→ 4 passed.flake8 push_notifications/admin.py tests/test_admin.pyandgit diff --check→ pass.Tests use local Django database records and stub only outbound provider sends; no external push was sent. AI assistance: Hermes helped implement and run the regression tests; the contribution is submitted under the repository's MIT license.