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

Changes to M2M fields from the reverse relation are logged incorrectly #665

Open
hackoder opened this issue Aug 26, 2024 · 1 comment
Open

Comments

@hackoder
Copy link

See here for minimal test showcasing the issue: hackoder@742bdf6

We track changes to Django user group memberships using:

auditlog.register(User, m2m_fields=["groups"])

and then Group membership changes are made in bulk using something like:

my_group.user_set.add(*list_of_users)

This results in the m2m_changed signal being fired from the reverse relationship (i.e. Group). Changes are logged against the Group model (instead of the User model), with the field_name also set to groups (a field that is non-existent on Group), and the actual objects pointing to user instances.

Note that the m2m_changed signal includes information specifying if its the reverse relationship (see: https://docs.djangoproject.com/en/4.2/ref/signals/#m2m-changed), however the code for logging m2m changes does not differentiate which side of the relationship is being updated.

IMO this should be updated so changes to the reverse side of the relationship are logged to the correct model (i.e. the side that has tracking for the field, or both if both sides are being tracked), and obviously using the right field names and pointing to the correct objects.

@DaBenjle
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@hackoder @DaBenjle and others