Skip to content

Conversation

@arthanson
Copy link
Collaborator

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.

@arthanson arthanson marked this pull request as ready for review January 30, 2024 18:02
Copy link
Member

@jeremystretch jeremystretch left a 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.

Comment on lines 78 to 87
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
)
Copy link
Member

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.

Copy link
Collaborator Author

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.

@jeremystretch jeremystretch merged commit 31fb696 into develop Feb 5, 2024
@jeremystretch jeremystretch deleted the 14947-changelog branch February 5, 2024 14:52
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Changelog entry missing for tag change

3 participants