-
Notifications
You must be signed in to change notification settings - Fork 21
Description
This follows the same line of thought as what I described in #157. It would be useful to optionally skip computation for specific fields during save(). This is especially helpful for simple count fields where the save() call is unlikely to affect the value, since the real updates happen through the m2m_changed signal.
We have started running into deadlocks caused by these computations on models that we save frequently. The simplest workaround would be to disable compute-on-save for our count fields, since none of them are influenced by the save itself. At the moment there does not seem to be a way to do this without skipping computed fields entirely for the model.
On a related note, it is unclear why the documentation recommends defining "self" in depends if computed fields are recalculated on every save regardless. I may be misunderstanding how this is intended to work. The field I am testing is recalculated on every save even though its depends definition only references a singular related field and does not include "self". I have always assumed that save() triggers recalculation regardless of depends, but now I am wondering why that is the case given that the "self" definition could make the behaviour more selective.
After thinking about this problem specifically, I figured that defining "self", possibly as an empty list or only id, would allow conditional computation and that the default behavior might be equivalent to [("self", "__all__")]. This does not seem to be the case. It may be that we need a new keyword argument for this, along with some clarification in the documentation, since maybe the expected behavior would be that a computed field only recalculates on save when a "self" field has changed, if you define "self".