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

Logs duplicated when used in conjunction with django-taggit and a custom tag model shared between models #685

Closed
cdubz opened this issue Nov 10, 2024 · 0 comments · Fixed by #686

Comments

@cdubz
Copy link
Contributor

cdubz commented Nov 10, 2024

I have a project using django-taggit that I'd like to add django-auditlog to.

In this project I'm using a custom tag model associated with numerous other models per django-taggit's documentation on how to use a custom tag.

For this use case, when using the m2m_fields configuration, I get N logs for each model registered with the connection tot custom tag. The log is correctly associated with the model the action occurred on, it just repeated N times.

This appears to happen because signal connection is made to the same m2m_model multiple times here --

m2m_changed.connect(
receiver,
sender=m2m_model,
dispatch_uid=self._dispatch_uid(m2m_changed, receiver),
)

Repro repo: https://github.com/babybuddy/django-auditlog-685/

hramezani pushed a commit that referenced this issue Nov 12, 2024
* fix: use sender for m2m signal dispatch connection

This fix adds support for a use case where a single m2m through model is
used on multiple models. When the reciever is used for the dispatch uid
in this use case it cause duplicated logs because the through model
singal connection happens multiple times.

By changing the m2m signal connection to use the sender for the dispatch
uid this duplication is prevented because the signal connection only
happens once for the through model.

Refs: #685

* fix(format): apply black formatting

* add test and changelog entry

* remove unused import

* correct import sorting

* move change log message to correct section
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

Successfully merging a pull request may close this issue.

1 participant