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

Incorrect field may be reported as changed by m2m_changed() signal handler #207

Open
JirkaV opened this issue Jan 3, 2022 · 3 comments
Open

Comments

@JirkaV
Copy link

JirkaV commented Jan 3, 2022

I have a situation where a specific model has multiple M2M relations to django User model. It may be an edge case, but I noticed that easyaudit reports just the first found m2m relation between my model and User model, no matter which of the M2M relations was altered.

After some digging I found out that this is caused by the fact that utils.get_m2m_field_name() which is called by model_signals.py.m2m_changed() returns the first m2m relation between found between the models even if there are multiple. The only place where the actual changed field can be detected from is in the sender argument to m2m_changed() which is currently being ignored.

As my case might be unusual, I'm not expecting a quick fix as this might be non-trivial. However created the issue in case someone else hits the same problem.

@lymanjohnson
Copy link

I believe I am also experiencing this issue, or something similar.

For me, the field name listed in the CRUDEvent's "field_changes" is the string "null". I can look at the CRUDEvent's object_json_repr and grab its m2m_rev_model which is the reverse model's app_label.model_name.

However, many of my models have double m2m relationships with each other, e.g. an Employee has two Location sets, their "Assigned Locations" and their "Supervised Locations". The CRUDEvent does not seem to contain sufficient information for me to see which of those sets was altered.

tl;dr It is quite difficult to see which m2m model was altered, and it is impossible to see which specific m2m relationship was altered.

@jheld
Copy link
Collaborator

jheld commented Oct 7, 2022

If anyone has the bandwidth to put up a draft PR, that would be appreciated. Even if you're unsure that you know how to effectively solve it, and even if you haven't added any tests, the contribution (at least pre-merge) is still encouraged and welcome.

@rgegriff
Copy link

@jheld Ran into a similar issue and opened up #270

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