Procházet zdrojové kódy

Fixes #6389: Call snapshot() on object when processing deletions

jeremystretch před 3 roky
rodič
revize
3a5914827b
2 změnil soubory, kde provedl 3 přidání a 4 odebrání
  1. 1 0
      docs/release-notes/version-3.3.md
  2. 2 4
      netbox/extras/signals.py

+ 1 - 0
docs/release-notes/version-3.3.md

@@ -4,6 +4,7 @@
 
 ### Bug Fixes
 
+* [#6389](https://github.com/netbox-community/netbox/issues/6389) - Call `snapshot()` on object when processing deletions
 * [#9878](https://github.com/netbox-community/netbox/issues/9878) - Fix spurious error message when rendering REST API docs
 * [#10579](https://github.com/netbox-community/netbox/issues/10579) - Mark cable traces terminating to a provider network as complete
 * [#10721](https://github.com/netbox-community/netbox/issues/10721) - Disable ordering by custom object field columns

+ 2 - 4
netbox/extras/signals.py

@@ -14,7 +14,6 @@ from .choices import ObjectChangeActionChoices
 from .models import ConfigRevision, CustomField, ObjectChange
 from .webhooks import enqueue_object, get_snapshots, serialize_for_webhook
 
-
 #
 # Change logging/webhooks
 #
@@ -100,9 +99,6 @@ def handle_deleted_object(sender, instance, **kwargs):
     """
     Fires when an object is deleted.
     """
-    if not hasattr(instance, 'to_objectchange'):
-        return
-
     # Get the current request, or bail if not set
     request = current_request.get()
     if request is None:
@@ -110,6 +106,8 @@ def handle_deleted_object(sender, instance, **kwargs):
 
     # Record an ObjectChange if applicable
     if hasattr(instance, 'to_objectchange'):
+        if hasattr(instance, 'snapshot') and not getattr(instance, '_prechange_snapshot', None):
+            instance.snapshot()
         objectchange = instance.to_objectchange(ObjectChangeActionChoices.ACTION_DELETE)
         objectchange.user = request.user
         objectchange.request_id = request.id