id,summary,reporter,owner,description,type,status,component,version,severity,resolution,keywords,cc,stage,has_patch,needs_docs,needs_tests,needs_better_patch,easy,ui_ux 18306,Deferred models should automatically issue update_fields when saving,Anssi Kääriäinen,Anssi Kääriäinen,"When saving a model fetched through deferred model loading (.only() or .defer()) and then saving these models it would be useful to issue an update_fields automatically. Currently, all the model's deferred fields are fetched from the DB and then saved back - this doesn't make sense. Instead, doing {{{ (assume Author with fields age + name) a = Author.objects.only('name').get(pk=1) a.name = 'Anssi' a.save() }}} should be equivalent to doing: {{{ a = Author.objects.only('name').get(pk=1) a.name = 'Anssi' a.save(update_fields=['name']) }}} In addition, the following must work: {{{ a = Author.objects.only('name').get(pk=1) a.name = 'Anssi' a.age = 31 a.save() }}} both age and name must be saved in this case. Also, if save is given update_fields argument, it must override the deferred model argument. I would like to investigate the possibility of storing the fields to update in model._state.update_fields - the reason is that this would be a nice hook for 3rd party model subclasses which could use that variable to implement automatic tracking of changed fields. There is a lot of discussion of this feature in #4102, and the decision there seems clear: we can't include automatic change tracking in Django core. However, allowing easy creation of state-tracking subclasses would be a nice addition.",Cleanup/optimization,closed,"Database layer (models, ORM)",dev,Normal,fixed,,niwi@…,Ready for checkin,1,0,0,0,0,0