Changes between Initial Version and Version 1 of Ticket #34733


Ignore:
Timestamp:
Jul 21, 2023, 5:57:09 PM (14 months ago)
Author:
Leif Kjos
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #34733

    • Property Owner changed from nobody to Leif Kjos
    • Property Status newassigned
  • Ticket #34733 – Description

    initial v1  
    33This poses a problem if the signal is supposed to run validation on the final state of the model. For example, let's say I have a model called `Customer` with a many-to-many relation to `SubscriptionPlan` and I have a `m2m_changed` signal that is supposed to validate if their SubscriptionPlan is valid.
    44
    5 If I call `subscription_plans.set([some_plans])`, the many-to-many manager will first call `subscription_plans.remove()` then `.add()` inside an atomic transaction. If my signal validates on the first `remove()`, it could be in an invalid state, even though it won't be by the time the `.add()` completes.
     5If I call `Customer.subscription_plans.set([some_plans])`, the many-to-many manager will first call `subscription_plans.remove()` then `.add()` inside an atomic transaction. If my signal validates on the first `.remove()`, it could be in an invalid state, even though it won't be by the time the `.add()` completes. However, I still need to be able to validate on the signal if the standard `.remove()` method is called.
    66
    77To get around this, I had to create a custom ManyToManyField with a custom RelatedManager that set an instance variable on the model when the `.set()` method was called. I'd like to propose adding a feature to the RelatedManager or to the signals to make the `m2m_changed` signal aware of if the `.set()` method was called when running. This could be a private attribute on the instance or extra information passed to the signal receiver.
Back to Top