Improve save() handling of deferred fields
|Reported by:||miracle2k||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||1.1|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Currently, when saving a model instance with deferred fields, all the missing fields are first pulled, one query each. This is not only very inefficient, of course, it also restricts the number of possible uses of the defer mechanism.
For example, django-denorm needs to do an additional query when saving a model with cache-fields to ensure that a potentially more recent value in the db is not overridden with a stale value on the field. If a field could just be excluded from save(), that would not be necessary.
I'm not familiar with the Django ORM code, but wouldn't it be straightforward to just skip fields that are not yet loaded during a save()?