Skip to content

fix: skip notification when community has no admin#161

Open
xenacode-art wants to merge 10 commits intom2b3:testfrom
xenacode-art:fix/null-admin-notification-guard
Open

fix: skip notification when community has no admin#161
xenacode-art wants to merge 10 commits intom2b3:testfrom
xenacode-art:fix/null-admin-notification-guard

Conversation

@xenacode-art
Copy link
Copy Markdown

While reading through the notification flow I noticed that in four places we call Notification.objects.create(user=community.admins.first(), ...) without checking whether admins.first() actually returned something. If a community has no assigned admin, that call gets user=None, hits an IntegrityError (or similar), and the surrounding except Exception just swallows it — so the notification disappears silently with only a log error to show for it. The fix is straightforward: pull admins.first() into a variable and guard the create() call behind an if admin: check.

Affected files:

  • articles/api.py — article submission notification
  • communities/articles_api.py — same, from the community side
  • communities/api_join.py — join request received notification
  • communities/api_invitation.py — invitation response notifications (two spots)

Worth noting: send_emails.py already does this correctly with an
if not admin guard — this PR brings the notification callsites in line
with that same pattern.

armanalam03 and others added 10 commits December 14, 2025 20:23
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.
@xenacode-art xenacode-art changed the base branch from main to test March 22, 2026 20:45
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.

2 participants