Tuesday, November 17, 2020

m2m_changed signal | Multiple m2m fields - fields' value overriding | DRF

Here's the task I'm trying to do:
m2m_changed.png
Full Code: test_django_project/m2m_change_triggers/models.py

Here's the issue: 2nd test in test_django_project/m2m_change_triggers/tests.py fails, but 1st one passes!

Did some digging and found that issue is probably here: rest_framework/serializers.py#L988-L990
The signal is called in both the tests, but `users` field modified by the signal is getting overriden by `field.set(value)` in `ModelSerializer` `save()`

- How do I solve the issue (both the tests should pass)?
- Is using signals the best approach here? Do I have an alternative?

How I've implemented the feature temporarily: using the same thing at the view-level, and not at the model-level.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3ff96667-d521-46a8-aecc-bd6a98c3225dn%40googlegroups.com.

No comments:

Post a Comment