Unnecessary changelog records for tag add/change/remove #4439

Closed
opened 2025-12-29 18:35:59 +01:00 by adam · 5 comments
Owner

Originally created by @netsandbox on GitHub (Jan 6, 2021).

Originally assigned to: @jeremystretch on GitHub.

Environment

  • Python version: 3.6.9
  • NetBox version: 2.10.3

Steps to Reproduce

  1. create two tags TagA and TagB
  2. create a virtual-machine (or device)
  3. add TagA to the virtual-machine
  4. remove TagA and add TagB to the virtual-machine (in one request)
  5. remove TagB from the virtual-machine

Expected Behavior

Steps 3., 4. and 5. create only one changelog record

Observed Behavior

Step 3. creates two changelog records (with the same request id), where only one record shows the tag add and one shows no change.

Step 4. creates three changelog records (with the same request id), where one record shows the TagA remove, one the TagB add, and one shows no change.

Step 5. creates two changelog records (with the same request id), where only one record shows the tag remove and one shows no change.

Here are the database extras_objectchange records for the above steps 2.-5.:
https://gist.github.com/cloos/e7dd4c3b1f064098e4250e7cddb29c85

Originally created by @netsandbox on GitHub (Jan 6, 2021). Originally assigned to: @jeremystretch on GitHub. <!-- NOTE: IF YOUR ISSUE DOES NOT FOLLOW THIS TEMPLATE, IT WILL BE CLOSED. This form is only for reporting reproducible bugs. If you need assistance with NetBox installation, or if you have a general question, please start a discussion instead: https://github.com/netbox-community/netbox/discussions Please describe the environment in which you are running NetBox. Be sure that you are running an unmodified instance of the latest stable release before submitting a bug report, and that any plugins have been disabled. --> ### Environment * Python version: 3.6.9 * NetBox version: 2.10.3 <!-- Describe in detail the exact steps that someone else can take to reproduce this bug using the current stable release of NetBox. Begin with the creation of any necessary database objects and call out every operation being performed explicitly. If reporting a bug in the REST API, be sure to reconstruct the raw HTTP request(s) being made: Don't rely on a client library such as pynetbox. --> ### Steps to Reproduce 1. create two tags TagA and TagB 2. create a virtual-machine (or device) 3. add TagA to the virtual-machine 4. remove TagA and add TagB to the virtual-machine (in one request) 5. remove TagB from the virtual-machine <!-- What did you expect to happen? --> ### Expected Behavior Steps 3., 4. and 5. create only **one** changelog record <!-- What happened instead? --> ### Observed Behavior Step 3. creates **two** changelog records (with the same request id), where only one record shows the tag add and one shows no change. Step 4. creates **three** changelog records (with the same request id), where one record shows the TagA remove, one the TagB add, and one shows no change. Step 5. creates **two** changelog records (with the same request id), where only one record shows the tag remove and one shows no change. Here are the database `extras_objectchange` records for the above steps 2.-5.: https://gist.github.com/cloos/e7dd4c3b1f064098e4250e7cddb29c85
adam added the type: bugstatus: accepted labels 2025-12-29 18:35:59 +01:00
adam closed this issue 2025-12-29 18:35:59 +01:00
Author
Owner

@jeremystretch commented on GitHub (Jan 7, 2021):

Multiple change records are created because tags (a many-to-many relationship) are added and removed using separate queries. I agree that it's not optimal but the necessary data is still captured. Attempting to consolidate these changes would likely take quite a bit of effort. If you'd like to volunteer for this work, I'll assign it to you. Otherwise, I don't think there's much to be done.

@jeremystretch commented on GitHub (Jan 7, 2021): Multiple change records are created because tags (a many-to-many relationship) are added and removed using separate queries. I agree that it's not optimal but the necessary data is still captured. Attempting to consolidate these changes would likely take quite a bit of effort. If you'd like to volunteer for this work, I'll assign it to you. Otherwise, I don't think there's much to be done.
Author
Owner

@netsandbox commented on GitHub (Jan 7, 2021):

I think it is ok for Step 4. to have two change records, one for tag remove and one for tag add.

But the additional change records in Step 3., 4., and 5. which shows no changes should not be created.
It's a little bit annoying when you try to inspect the object changes and always have change records which shows no object changes. Also if you frequently change tags, this unnecessarily increases the extras_objectchange table.

Sadly my knowledge of the NetBox code is not good enough to fix this myself in a reasonable time.

@netsandbox commented on GitHub (Jan 7, 2021): I think it is ok for Step 4. to have two change records, one for tag remove and one for tag add. But the additional change records in Step 3., 4., and 5. which shows no changes should not be created. It's a little bit annoying when you try to inspect the object changes and always have change records which shows no object changes. Also if you frequently change tags, this unnecessarily increases the extras_objectchange table. Sadly my knowledge of the NetBox code is not good enough to fix this myself in a reasonable time.
Author
Owner

@patrickfnielsen commented on GitHub (Feb 18, 2021):

I agree with @netsandbox, there's no reason to create a log entry if there's no changes.
The best solution I could find with my limited knowledge of the system, is to check if there's any diff between the objects before creating a ObjectChanges - This has the drawback of requiring an extra db call.

@jeremystretch Is this something that you would accept a PR for? In my limited testing it seems to fix the problem, but I'm not sure if theres any other drawbacks of doing it this way.

@patrickfnielsen commented on GitHub (Feb 18, 2021): I agree with @netsandbox, there's no reason to create a log entry if there's no changes. The best solution I could find with my limited knowledge of the system, is to check if there's any diff between the objects before creating a ObjectChanges - This has the drawback of requiring an extra db call. @jeremystretch Is [this](https://github.com/patrickfnielsen/netbox/commit/fdf5077e9af46d7cbee47bd8f38e2316b740d428) something that you would accept a PR for? In my limited testing it seems to fix the problem, but I'm not sure if theres any other drawbacks of doing it this way.
Author
Owner

@jeremystretch commented on GitHub (Apr 13, 2021):

With the improvements made to change logging in v2.11 (see #5913), we should be able to update the first ObjectChange instance on m2m_changed instead of creating a second instance. I'm going to dig into this a bit more.

@jeremystretch commented on GitHub (Apr 13, 2021): With the improvements made to change logging in v2.11 (see #5913), we should be able to update the first ObjectChange instance on `m2m_changed` instead of creating a second instance. I'm going to dig into this a bit more.
Author
Owner

@jeremystretch commented on GitHub (Apr 13, 2021):

This will be fixed in the upcoming v2.11 release.

@jeremystretch commented on GitHub (Apr 13, 2021): This will be fixed in the upcoming v2.11 release.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#4439