Notifications are automatically deleted when an associated object is deleted (in some cases) #10057

Closed
opened 2025-12-29 21:26:17 +01:00 by adam · 0 comments
Owner

Originally created by @jeremystretch on GitHub (Aug 7, 2024).

Originally assigned to: @jeremystretch on GitHub.

Deployment Type

NetBox Cloud

NetBox Version

v4.1-beta1

Python Version

3.10

Steps to Reproduce

  1. Manually create a Notification associated with an object (e.g. a site)
  2. Manually delete that object via the shell

Expected Behavior

The notification should persist, relying on the captured static representation of the object to denote the association.

Observed Behavior

The notification is deleted automatically, due to the generic relation on NotificationsMixin:

Note also, that if you delete an object that has a GenericRelation, any objects which have a GenericForeignKey pointing at it will be deleted as well.
...
Unlike ForeignKey, GenericForeignKey does not accept an on_delete argument to customize this behavior.

Originally created by @jeremystretch on GitHub (Aug 7, 2024). Originally assigned to: @jeremystretch on GitHub. ### Deployment Type NetBox Cloud ### NetBox Version v4.1-beta1 ### Python Version 3.10 ### Steps to Reproduce 1. Manually create a Notification associated with an object (e.g. a site) 2. Manually delete that object via the shell ### Expected Behavior The notification should persist, relying on the captured static representation of the object to denote the association. ### Observed Behavior The notification is deleted automatically, due to the [generic relation](https://docs.djangoproject.com/en/5.0/ref/contrib/contenttypes/#reverse-generic-relations) on NotificationsMixin: > Note also, that if you delete an object that has a [GenericRelation](https://docs.djangoproject.com/en/5.0/ref/contrib/contenttypes/#django.contrib.contenttypes.fields.GenericRelation), any objects which have a [GenericForeignKey](https://docs.djangoproject.com/en/5.0/ref/contrib/contenttypes/#django.contrib.contenttypes.fields.GenericForeignKey) pointing at it will be deleted as well. > ... > Unlike [ForeignKey](https://docs.djangoproject.com/en/5.0/ref/models/fields/#django.db.models.ForeignKey), [GenericForeignKey](https://docs.djangoproject.com/en/5.0/ref/contrib/contenttypes/#django.contrib.contenttypes.fields.GenericForeignKey) does not accept an [on_delete](https://docs.djangoproject.com/en/5.0/ref/models/fields/#django.db.models.ForeignKey.on_delete) argument to customize this behavior.
adam added the type: bugstatus: acceptedbetaseverity: medium labels 2025-12-29 21:26:17 +01:00
adam closed this issue 2025-12-29 21:26:18 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#10057