From 703323038888a983dd3a5d9cee2a7439965df778 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Fri, 22 Aug 2025 19:13:24 -0400 Subject: [PATCH] Fixes #20157: Overwrite existing user notifications to avoid duplications (#20167) --- netbox/extras/models/notifications.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/netbox/extras/models/notifications.py b/netbox/extras/models/notifications.py index 44874a4c8..3c8bd411b 100644 --- a/netbox/extras/models/notifications.py +++ b/netbox/extras/models/notifications.py @@ -173,14 +173,17 @@ class NotificationGroup(ChangeLoggedModel): User.objects.filter(groups__in=self.groups.all()) ).order_by('username') - def notify(self, **kwargs): + def notify(self, object_type, object_id, **kwargs): """ Bulk-create Notifications for all members of this group. """ - Notification.objects.bulk_create([ - Notification(user=member, **kwargs) - for member in self.members - ]) + for user in self.members: + Notification.objects.update_or_create( + object_type=object_type, + object_id=object_id, + user=user, + defaults=kwargs + ) notify.alters_data = True