#18306: Deferred models should automatically issue update_fields when saving -------------------------------------+------------------------------------- Reporter: akaariai | Owner: akaariai Type: | Status: new Cleanup/optimization | Version: master Component: Database layer | Resolution: (models, ORM) | Triage Stage: Accepted Severity: Normal | Needs documentation: 0 Keywords: | Patch needs improvement: 1 Has patch: 1 | UI/UX: 0 Needs tests: 0 | Easy pickings: 0 | -------------------------------------+------------------------------------- Changes (by akaariai):
* needs_better_patch: 0 => 1 Comment: I spotted two issues: 1. When doing a deferred model .save() with using argument, where the using is to other database than where the object was fetched, the "update_fields" machinery should not be used. This is a minor corner case, but should still work. 2. The "deferred fields" is remembered in instance._meta, and it is altered when a field is set to a value - this results in changing the "deferred fields" property for _all_ instances, not just for the instance which was changed. This is a blocker issue. I see two ways forward: - remember the loaded fields (instead of deferred fields) in instance._state instead of instance._meta. - do not remember the deferred fields at all. Instead check just for instance._deferred. If set, then go through all fields and check if any of the fields are instances of !DeferredAttribute. Those fields which are instances of !DeferredAttribute are the deferred fields. The second approach should be very robust, and I think it should be used. The check to use is: {{{ for field in self._meta.fields: if isinstance(self.__class__.__dict__.get(field.attname), DeferredAttribute): # add to deferred fields. }}} See: https://github.com/akaariai/django/tree/ticket_18306 for details. There are also some other added tests. I stumbled upon other issues while working on this ticket, see https://github.com/akaariai/django/tree/defer_inheritance_pk, #18343. Some (well at least one) of the added tests need this work to pass. -- Ticket URL: <https://code.djangoproject.com/ticket/18306#comment:7> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.