loaddata failure if model has overridden save() method
|Reported by:||Russell Keith-Magee||Owned by:||Russell Keith-Magee|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
If a model overrides the save() method, and performs a query in that save(), loaddata may fail when objects of that type are loaded. dumpdata/loaddata don't preserve dependency order (they can't really, because there could easily be circular dependencies), so loaddata can't guarantee that the subject of the search will have been deserialized yet.
I suspect that the fix for this is to introduce a 'raw save' - a guaranteed use of the original Model.save(), rather than the model's overidden variant.
raw_save should proabably also avoid running pre-save methods on fields - these methods can mutate the data as part of the load (e.g., you can't correctly deserialize an auto_add_now field, as deserializing will update the field).
The errors reported by #4431 are a direct cause of this problem.