Internal Server Error when using a user group in a notification group used for object change notifications #11520

Closed
opened 2025-12-29 21:46:20 +01:00 by adam · 1 comment
Owner

Originally created by @peteeckel on GitHub (Aug 22, 2025).

Originally assigned to: @jeremystretch on GitHub.

Deployment Type

Self-hosted

NetBox Version

v4.3.6

Python Version

3.11

Steps to Reproduce

  1. Create a group "Administrators" and add the "admin" user
  2. Create a notification group "Admin Notifications" and add the group "Administrators"
  3. Create an event rule "IP Address Notifications" for "IPAM -> IPAddress" objects and at least event type "Object updated"
  4. Create a new IP address
  5. Edit the IP address and change something (e.g. the description)

Expected Behavior

The IP address is modified and a notification about the update is sent to the admin user.

Observed Behavior

An exception is raised:

Traceback (most recent call last):
  File "/opt/netbox/lib64/python3.11/site-packages/django/db/backends/utils.py", line 105, in _execute
    return self.cursor.execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/lib64/python3.11/site-packages/psycopg/cursor.py", line 97, in execute
    raise ex.with_traceback(None)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The above exception (duplicate key value violates unique constraint "extras_notification_unique_per_object_and_user"
DETAIL:  Key (object_type_id, object_id, user_id)=(69, 19, 1) already exists.) was the direct cause of the following exception:
  File "/opt/netbox/lib64/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/netbox/netbox/middleware.py", line 39, in __call__
    with ExitStack() as stack:
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/contextlib.py", line 589, in __exit__
    raise exc_details[1]
    ^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/contextlib.py", line 574, in __exit__
    if cb(*exc_details):
       ^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/contextlib.py", line 144, in __exit__
    next(self.gen)
    ^^^^^^^^^^^^^^
  File "/opt/netbox/netbox/netbox/context_managers.py", line 24, in event_tracking
    flush_events(events)
    ^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/netbox/extras/events.py", line 194, in flush_events
    func(events)
    ^^^^^^^^^^^^
  File "/opt/netbox/netbox/extras/events.py", line 175, in process_event_queue
    process_event_rules(
    ^
  File "/opt/netbox/netbox/extras/events.py", line 143, in process_event_rules
    event_rule.action_object.notify(
    ^
  File "/opt/netbox/netbox/extras/models/notifications.py", line 180, in notify
    Notification.objects.bulk_create([
    ^^
  File "/opt/netbox/lib64/python3.11/site-packages/django/db/models/manager.py", line 87, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/lib64/python3.11/site-packages/django/db/models/query.py", line 823, in bulk_create
    returned_columns = self._batched_insert(
                       
  File "/opt/netbox/lib64/python3.11/site-packages/django/db/models/query.py", line 1896, in _batched_insert
    self._insert(
    ^
  File "/opt/netbox/lib64/python3.11/site-packages/django/db/models/query.py", line 1868, in _insert
    return query.get_compiler(using=using).execute_sql(returning_fields)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/lib64/python3.11/site-packages/django/db/models/sql/compiler.py", line 1882, in execute_sql
    cursor.execute(sql, params)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/lib64/python3.11/site-packages/django/db/backends/utils.py", line 122, in execute
    return super().execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/lib64/python3.11/site-packages/django/db/backends/utils.py", line 79, in execute
    return self._execute_with_wrappers(
           
  File "/opt/netbox/lib64/python3.11/site-packages/django/db/backends/utils.py", line 92, in _execute_with_wrappers
    return executor(sql, params, many, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/lib64/python3.11/site-packages/django/db/backends/utils.py", line 100, in _execute
    with self.db.wrap_database_errors:
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/lib64/python3.11/site-packages/django/db/utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/lib64/python3.11/site-packages/django/db/backends/utils.py", line 105, in _execute
    return self.cursor.execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/lib64/python3.11/site-packages/psycopg/cursor.py", line 97, in execute
    raise ex.with_traceback(None)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Exception Type: IntegrityError at /ipam/ip-addresses/19/edit/
Exception Value: duplicate key value violates unique constraint "extras_notification_unique_per_object_and_user"
DETAIL:  Key (object_type_id, object_id, user_id)=(69, 19, 1) already exists.
Originally created by @peteeckel on GitHub (Aug 22, 2025). Originally assigned to: @jeremystretch on GitHub. ### Deployment Type Self-hosted ### NetBox Version v4.3.6 ### Python Version 3.11 ### Steps to Reproduce 1. Create a group "Administrators" and add the "admin" user 2. Create a notification group "Admin Notifications" and add the group "Administrators" 3. Create an event rule "IP Address Notifications" for "IPAM -> IPAddress" objects and at least event type "Object updated" 4. Create a new IP address 5. Edit the IP address and change something (e.g. the description) ### Expected Behavior The IP address is modified and a notification about the update is sent to the admin user. ### Observed Behavior An exception is raised: ``` Traceback (most recent call last): File "/opt/netbox/lib64/python3.11/site-packages/django/db/backends/utils.py", line 105, in _execute return self.cursor.execute(sql, params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/netbox/lib64/python3.11/site-packages/psycopg/cursor.py", line 97, in execute raise ex.with_traceback(None) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The above exception (duplicate key value violates unique constraint "extras_notification_unique_per_object_and_user" DETAIL: Key (object_type_id, object_id, user_id)=(69, 19, 1) already exists.) was the direct cause of the following exception: File "/opt/netbox/lib64/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner response = get_response(request) ^^^^^^^^^^^^^^^^^^^^^ File "/opt/netbox/netbox/netbox/middleware.py", line 39, in __call__ with ExitStack() as stack: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib64/python3.11/contextlib.py", line 589, in __exit__ raise exc_details[1] ^^^^^^^^^^^^^^^^^^^^ File "/usr/lib64/python3.11/contextlib.py", line 574, in __exit__ if cb(*exc_details): ^^^^^^^^^^^^^^^^ File "/usr/lib64/python3.11/contextlib.py", line 144, in __exit__ next(self.gen) ^^^^^^^^^^^^^^ File "/opt/netbox/netbox/netbox/context_managers.py", line 24, in event_tracking flush_events(events) ^^^^^^^^^^^^^^^^^^^^ File "/opt/netbox/netbox/extras/events.py", line 194, in flush_events func(events) ^^^^^^^^^^^^ File "/opt/netbox/netbox/extras/events.py", line 175, in process_event_queue process_event_rules( ^ File "/opt/netbox/netbox/extras/events.py", line 143, in process_event_rules event_rule.action_object.notify( ^ File "/opt/netbox/netbox/extras/models/notifications.py", line 180, in notify Notification.objects.bulk_create([ ^^ File "/opt/netbox/lib64/python3.11/site-packages/django/db/models/manager.py", line 87, in manager_method return getattr(self.get_queryset(), name)(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/netbox/lib64/python3.11/site-packages/django/db/models/query.py", line 823, in bulk_create returned_columns = self._batched_insert( File "/opt/netbox/lib64/python3.11/site-packages/django/db/models/query.py", line 1896, in _batched_insert self._insert( ^ File "/opt/netbox/lib64/python3.11/site-packages/django/db/models/query.py", line 1868, in _insert return query.get_compiler(using=using).execute_sql(returning_fields) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/netbox/lib64/python3.11/site-packages/django/db/models/sql/compiler.py", line 1882, in execute_sql cursor.execute(sql, params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/netbox/lib64/python3.11/site-packages/django/db/backends/utils.py", line 122, in execute return super().execute(sql, params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/netbox/lib64/python3.11/site-packages/django/db/backends/utils.py", line 79, in execute return self._execute_with_wrappers( File "/opt/netbox/lib64/python3.11/site-packages/django/db/backends/utils.py", line 92, in _execute_with_wrappers return executor(sql, params, many, context) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/netbox/lib64/python3.11/site-packages/django/db/backends/utils.py", line 100, in _execute with self.db.wrap_database_errors: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/netbox/lib64/python3.11/site-packages/django/db/utils.py", line 91, in __exit__ raise dj_exc_value.with_traceback(traceback) from exc_value ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/netbox/lib64/python3.11/site-packages/django/db/backends/utils.py", line 105, in _execute return self.cursor.execute(sql, params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/netbox/lib64/python3.11/site-packages/psycopg/cursor.py", line 97, in execute raise ex.with_traceback(None) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Exception Type: IntegrityError at /ipam/ip-addresses/19/edit/ Exception Value: duplicate key value violates unique constraint "extras_notification_unique_per_object_and_user" DETAIL: Key (object_type_id, object_id, user_id)=(69, 19, 1) already exists. ```
adam added the type: bugstatus: acceptedseverity: medium labels 2025-12-29 21:46:20 +01:00
adam closed this issue 2025-12-29 21:46:20 +01:00
Author
Owner

@jeremystretch commented on GitHub (Aug 22, 2025):

Note: This occurs only on the second modification, when a notification is already present for the same object.

@jeremystretch commented on GitHub (Aug 22, 2025): Note: This occurs only on the _second_ modification, when a notification is already present for the same object.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11520