-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
14947 fix for missing changelog if only update m2m #14986
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also extend the change logging tests to check for a condition where only the tags of an item are changed.
netbox/extras/signals.py
Outdated
if not qs: | ||
objectchange = instance.to_objectchange(action) | ||
if objectchange and objectchange.has_changes: | ||
objectchange.user = request.user | ||
objectchange.request_id = request.id | ||
objectchange.save() | ||
else: | ||
qs.update( | ||
postchange_data=instance.to_objectchange(action).postchange_data | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can clean this up a bit using the update_or_create()
queryset method to automatically create a new change record where needed. We can also pull objectchange = instance.to_objectchange(action)
up to the top, as it appears to be needed under every condition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved the objectchange = line.
For update_or_create I don't think that would be any cleaner as on create you are doing objectchange.save and not specifying all the fields. For update_or_create you would need to specify all the fields for defaults and create_defaults which is sort of duplicating instance.to_objectchange.
Fixes: #14947
Fix for missing changelog if only update m2m (tag). Issue is if you only update tags (no other edits) then the changelog entry for the post_save (not m2m_changed) is not created because there are no changes at that point. When the m2m_changed comes in the update does not work because the query is empty.
Fix is if there is an m2m change and there isn't an existing objectchange then create one, otherwise do the update.