Create proper change log data when updating objects in custom scripts with NetBox 2.11 #6491
-
Hi, in NetBox 2.10.10 the following worked in a custom script and created proper change log records: ip_address = IPAddress.objects.get(address="192.168.178.10/24")
ip_address.dns_name = "example.com"
ip_address.save() In NetBox 2.11.4 the above creates a change log record without Pre-Change Data and Difference. ip_address = IPAddress.objects.get(address="192.168.178.10/24")
ip_address.snapshot()
ip_address.dns_name = "example.com"
ip_address.save() Is this the correct way? 9c967ee created a ip_address = IPAddress.objects.get_object_with_snapshot(address="192.168.178.10/24")
ip_address.dns_name = "example.com"
ip_address.save() And this should be also documented at https://netbox.readthedocs.io/en/stable/additional-features/custom-scripts/. In some custom scripts I use the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Snapshots aren't taken automatically because doing so effectively saves a copy of the object on itself. This is obviously wasteful if scenarios where there's no intent to modify and save the object.
Yes, calling
It's probably worth discussing further as a feature request.
Yes, because it's not possible to capture the pre-change state of an object when writing to the database directly. |
Beta Was this translation helpful? Give feedback.
Snapshots aren't taken automatically because doing so effectively saves a copy of the object on itself. This is obviously wasteful if scenarios where there's no intent to modify and save the object.
Yes, calling
snapshot()
on the instance will capture the pre-change data.It's probably worth discussing further as a feature request.
Yes, because it's not possible to capture the pre-change state of an object when writing to the database directly.