| | 219 | |
| | 220 | == Tips and Troubleshooting == |
| | 221 | |
| | 222 | === Help, post_save seems to be emitted twice for each save! === |
| | 223 | |
| | 224 | The source of this is documented nicely in #3951 and solved in #6814 (AKA Signals-refactor, r8223). |
| | 225 | |
| | 226 | The 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 | |
| | 230 | The 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. |