Opened 7 years ago
Last modified 7 years ago
#28970 closed New feature
Option to suppress signals on save to avoid loop — at Version 1
Reported by: | Gustavo Henrique de Almeida Gonçalves | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 2.0 |
Severity: | Normal | Keywords: | signal suppress save recursion loop problem |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Calling instance.save()
inside a post_save signal receiver causes a loop and max recursion error. This problem is very easy to fall into and the best solution at the moment is call the QuerySet update()
method, so that the post_save signal is not called in this case.
This is a very ugly workaround. I think Django should give the option to call save()
and explicitly suppress signal emitting. For example:
instance.save(post_save=False)
In the above method call, post_save signal would not be sent, and the loop problem would not occurs.
Resaving the object in
post_save()
doesn't sound like a common use case (or a wise thing to do, from a performance standpoint). Can you explain your use case?