Changes between Version 31 and Version 32 of Signals


Ignore:
Timestamp:
Aug 25, 2008, 1:06:28 PM (16 years ago)
Author:
Idan Gazit
Comment:

Added a tip about using dispatch_uid to prevent double-dispatch of signals

Legend:

Unmodified
Added
Removed
Modified
  • Signals

    v31 v32  
    217217|| {{{dispatcher.send(my_signal, sender)}}} || {{{my_signal.send(sender)}}} ||
    218218|| {{{dispatcher.connect(my_handler, my_signal, sender=Any)}}} || {{{my_signal.connect(my_handler, sender=None)}}} ||
     219
     220== Tips and Troubleshooting ==
     221
     222=== Help, post_save seems to be emitted twice for each save! ===
     223
     224The source of this is documented nicely in #3951 and solved in #6814 (AKA Signals-refactor, r8223).
     225
     226The short of it is that the signal is bound twice due to double-importing of whatever module is doing the binding. The workaround is to pass `dispatch_uid="some.unique.identifier"` when binding signals:
     227
     228{{{signals.post_save.connect(my_handler, MyModel, dispatch_uid="path.to.this.module")}}}
     229
     230The dispatch_uid string can be any unique string. Since the goal is to prevent connect() from being called twice due to its parent module being imported twice, a good value to use for dispatch_uid is the module's name or path. However, dispatch_uid can be any unique identifier. The net effect is that `signals.signal_name.connect` will only bind the signal once for each dispatch_uid, even if `connect` is called multiple times.
    219231
    220232== Other documentation ==
Back to Top