-
Notifications
You must be signed in to change notification settings - Fork 165
Log adding participants via User Profile edit page #2412
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
Conversation
|
I first had an implementation to not hardcode "participants" field in the forms.py: if added_evaluations or removed_evaluations:
example_evaluation = next(iter(added_evaluations | removed_evaluations), None)
if example_evaluation and isinstance(example_evaluation, LoggedModel):
for field in type(example_evaluation)._meta.many_to_many:
related_model = getattr(field.remote_field, "model", None)
if isinstance(self.instance, related_model):
field_name = field.name
breakBut this would find any M2M field in the Evaluation Model, that has a UserProfile Model. |
|
I don't know if you discussed this already with the others, but I would think that we want to change this behavior in general. From what I can tell, our current code just doesn't handle the case where these log entries would be generated: EvaP/evap/evaluation/models_logging.py Lines 344 to 347 in 65863d4
From https://docs.djangoproject.com/en/5.1/ref/signals/#m2m-changed I would expect that this branch is taken when an edit like in our issue here is performed. Note that ephios, where the author of the whole logging business kept expanding this system, does not care about this: https://github.com/ephios-dev/ephios/blob/7af3a1fbc091cd38062b68f5a6904e503c4cb013/ephios/modellogging/recorders.py#L262 |
|
yes @niklasmohrin that was my first idea as well but see commit where i removed general implementation. As explained in the commit message can pk_set be None so I would have to add a pk_set is None check. But this would defeat the purpose of a general implementation since some changes would not be logged. |
|
Ah, right. Still, if the action is pre_clear, then we should be able to find which objects are related. My intuition is that Django sets |
|
After some reading, came up with this implementation. This is pretty similar to the previous one (see here). The sender is always the M2M "table" which gets changed (so the through model). Here this would be field = model._meta.get_field(field_name)
related_name = field.remote_field.get_accessor_name()We can get the defined When I left the preivous commits if you want to compare with the new implementation :). |
|
Should I put an similar version of the tests into |
|
Impressive work on code and explanation so far, very well done! Just to loop you in, I think that this is probably the right solution, but didn't want to give an approval yet as this is a very critical code area and I want to briefly discuss with @richardebeling and you on Monday to ensure we are all on the same page about the changes and consequences |
richardebeling
left a comment
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.
looking mostly good, thanks
| if pk_set: | ||
| related_instances = model.objects.filter(pk__in=pk_set) | ||
| else: | ||
| # When action is pre_clear, pk_set is None, so we need to get the related instances from the instance itself | ||
| related_instances = getattr(instance, related_name).all() |
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.
My biggest concern is that related_instances is big, causing us to do hundreds of db queries here, slowing down a form save unreasonably.
The current ManyToManyFields we have are:
- UserProfile:
cc_users,delegates: should be small - Contribution:
questionnaires: should be small - Course:
programs,responsibles: should be small (programs might be an issue in bigger universities) - Evaluation:
participants,voters- For
participants, we only except a single user to participate in a small number of evaluations, so reverse-removing/adding should only trigger a small amount of log entries.
votersis inunlogged_fields
- For
-> Change here is fine with me for now, but I think we might set ourselves up for performance issues in the future. We'll see.
9d279d9 to
f09f831
Compare
- test if adding a user to an evaluation via the user edit page creates a log entry - test if the logging implementations respects unlogged_fields
richardebeling
left a comment
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.
Lgtm
Note that rebasing/squashing commits makes reviewing incremental changes that happened since the last review harder. GitHub only tracks review progress as a boolean status per file, so for a one-line change in a file, we have to read through the whole file again. It's more reviewer-friendly to not rebase after the first full code review until everything is approved.
richardebeling
left a comment
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.
thanks :)
niklasmohrin
left a comment
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.
Thanks!
@janno42 My gut feeling is like last time, if we want to release a bugfix release I would hold this PR back just in case. 2025.7 can be the time of reverse logging and dropped courses. But do with it what you want
This is technically also a bugfix because the related issue is a bug :) |
fix #2381