fix: skip notification when community has no admin#161
Open
xenacode-art wants to merge 10 commits intom2b3:testfrom
Open
fix: skip notification when community has no admin#161xenacode-art wants to merge 10 commits intom2b3:testfrom
xenacode-art wants to merge 10 commits intom2b3:testfrom
Conversation
Sync Alphatest with Test
Sync Main with AlphaTest
Sync test with alphatest
Sync main with Alphatest
Sync AlphaTest with Test
Sync Main with Alphatest
change MAX_COMMUNITIES_PER_USER to 40
change MAX_COMMUNITIES_PER_USER to 40
`admins.first()` returns None on communities with no assigned admin, which then gets passed as the `user` field to `Notification.objects.create`. That silently fails (the exception is caught and swallowed) so the notification just disappears with no trace except a log error. Fixed by extracting the result of `admins.first()` into a variable and only creating the notification when it's not None. Affects four call sites across articles and communities. Closes no issue — found while reading the notification flow.
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.
While reading through the notification flow I noticed that in four places we call
Notification.objects.create(user=community.admins.first(), ...)without checking whetheradmins.first()actually returned something. If a community has no assigned admin, that call getsuser=None, hits an IntegrityError (or similar), and the surroundingexcept Exceptionjust swallows it — so the notification disappears silently with only a log error to show for it. The fix is straightforward: pulladmins.first()into a variable and guard thecreate()call behind anif admin:check.Affected files:
articles/api.py— article submission notificationcommunities/articles_api.py— same, from the community sidecommunities/api_join.py— join request received notificationcommunities/api_invitation.py— invitation response notifications (two spots)Worth noting:
send_emails.pyalready does this correctly with anif not adminguard — this PR brings the notification callsites in linewith that same pattern.