Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object's changelog shows incorrect information about its tag(s) updates #499

Closed
david-kn opened this issue May 27, 2021 · 2 comments · Fixed by #558
Closed

Object's changelog shows incorrect information about its tag(s) updates #499

david-kn opened this issue May 27, 2021 · 2 comments · Fixed by #558
Labels
type: bug Something isn't working as expected

Comments

@david-kn
Copy link
Contributor

Hi, I found some incorrect behaviour of changelogs.

Environment

  • Python version: 3.6.8
  • Nautobot version: v1.0.1

Steps to Reproduce

  1. Let's create an object in Nautobot - IP address, e.g. 127.0.0.1 that has a tag attached + some attributes e.g name, description (I was testing this also on a VLAN and presumably it relates to all object types with tags.)

  2. Modify this object's attribute(s) - let's say description field (do not modify the tags!) via API request.

curl --location --request PATCH 'https://nautobot-test.my-domain.com/api/ipam/ip-addresses/c80cb26c-9c8f-4099-93ff-97f01d106c7b/' \
--header 'Authorization: Token 123' \
--header 'Content-Type: application/json' \
--data-raw '{
    "description": "test 1"
}'

01_changelog_issue

This creates a changelog showing that not only the description was changed but also that tags were removed by this person in this update. (first changelog incorrect information)
Just fyi: this happens either via pynautobot or simple patch request (e.g. via Postman). I'm adding this piece of information here because it is quite relevant information for a "workaround" that I found.

  1. Update a description field once more via API
curl --location --request PATCH 'https://nautobot-test.my-domain.com/api/ipam/ip-addresses/c80cb26c-9c8f-4099-93ff-97f01d106c7b/' \
--header 'Authorization: Token 123' \
--header 'Content-Type: application/json' \
--data-raw '{
    "description": "another test"
}'

Changelog seems fine at a first sight. Only description is changed as it treats somehow the object as being without tags! Although those are still visible in GUI

02_changelog_ok

(Well, anyway, omitting the changelog information the actual state of the object is as expected - description is modified and the tags are as they were)

03_nautobot_gui

  1. Modify the object's description via Nautobot GUI.
    As soon as someone modifies the same object via Nautobot GUI - even an "empty update" or simply just change some field only then a new changelog record is created and it will show that this update actually added 'new tags' (those that were and still are attached to the object and those that appeared to be removed in the second step) (second changelog incorrect information)

04_nautobot_changelog_issue

Expected Behavior

The changelog records for each action should show only the changes that were actually made by that user within that particular update.

Observed Behavior

The changelog produces incorrect logs about user actions (removing and adding tags to the object) that a user simply didn't do. (And that also did not happen "under the hood" due to same inner chain of relationships because the object actually keeps the tag(s) unchanged).


Other findings / Possible "workaround"
Because I needed to find a way if it is possible to keep data consistent as well as logs (which are very important for keeping an eye on a history of changes) I found out that Nautobot treats differently Patch request's attributes which are passed.
Normally and for all the data (except tags) only those data present in the patch request are updated and others are untouched (expected behaviour). Nevertheless, for tags - empty tags mean "removing" them (well, only in changelog though). In order to make tags look untouched also in the logs, they have to be sent also in the path request (e.g. their IDs). Then the tags will remain in the object and the log will not look like that the tags were updated.

curl --location --request PATCH 'https://nautobot-test.my-domain.com/api/ipam/ip-addresses/c80cb26c-9c8f-4099-93ff-97f01d106c7b/' \
--header 'Authorization: Token 123' \
--header 'Content-Type: application/json' \
--data-raw '{
    "description": "final test",
    "tags": ["f03aba43-8df8-5a35-8345-d78eca7d95b9"]
}'

Well, and this approach is possible only for direct API request but not for pyautobot. Because as I found out, pynautobot library does some pre-checks and the tags which seems to be already presented in the object are removed from a request before the patch request is sent... Hence it is not possible to use pynautobot and successfully update nautobot object keeping information about tags true in logs. It is possible though to do so at least with this workaround while using requests library or Postman etc.

@glennmatthews
Copy link
Contributor

netbox-community/netbox#6492 seems very similar - may be able to derive something from its fix?

@david-kn
Copy link
Contributor Author

david-kn commented Jun 4, 2021

Yes, this seems very alike or actually identical issue.
Don't know how much does the nautobot code base differ in this case but I assume that this one line modification could fix it also for Nautobot? ;-)

jathanism added a commit that referenced this issue Jun 15, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug Something isn't working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants