Django

Code

Ticket #13087 (closed: fixed)

Opened 5 months ago

Last modified 4 months ago

m2m_changed fires before a clear but after add/remove

Reported by: rcatherman Assigned to: nobody
Milestone: 1.2 Component: Database layer (models, ORM)
Version: 1.2-beta Keywords:
Cc: Triage Stage: Design decision needed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

In db/models/fields/related.py I notice that _add_items and _remove_items perform the db actions and then fire the signal to the m2m_changed listeners. _clear_items fires the signal prior to the db interaction. The result is inconsistent. For my use case, I'd like to have my listener assert a relationship has at least one particular item no matter if it is accidentily cleared. It works on removal, but not on clear because I notice the DELETE happens after my re-INSERT.

I've made the change here and it works as expected now.

Attachments

Change History

03/12/10 10:55:03 changed by russellm

  • needs_better_patch changed.
  • needs_docs changed.
  • stage changed from Unreviewed to Design decision needed.
  • needs_tests changed.
  • milestone set to 1.2.

This certainly needs to be decided before 1.2. The current behaviour is deliberate, and documented as implemented; I need to think about this (preferably with a clear head) to determine if the current behavior is the most desirable.

03/12/10 10:55:59 changed by russellm

  • component changed from Uncategorized to Database layer (models, ORM).

03/26/10 09:52:29 changed by malcalypse

  • owner changed from nobody to malcalypse.
  • status changed from new to assigned.

03/26/10 10:49:10 changed by malcalypse

  • owner changed from malcalypse to nobody.
  • status changed from assigned to new.

03/27/10 07:02:50 changed by gav

Why not do both? We have pre/post-save, and pre/post-delete. So, pre/post-m2m_changed would be very much in line with what Django already has.

03/30/10 06:54:57 changed by russellm

  • status changed from new to closed.
  • resolution set to fixed.

(In [12888]) Fixed #13087 -- Modified m2m signals to provide greater flexibility over exactly when notifications are delivered.

This is a BACKWARDS INCOMPATIBLE CHANGE for anyone using the signal names introduced in r12223.

  • If you were listening to "add", you should now listen to "post_add".
  • If you were listening to "remove", you should now listen to "post_remove".
  • If you were listening to "clear", you should now listen to "pre_clear".

You may also want to examine your code to see whether the "pre_add", "pre_remove" or "post_clear" would be better suited to your application.


Add/Change #13087 (m2m_changed fires before a clear but after add/remove)




Change Properties
Action