Changes between Initial Version and Version 1 of Ticket #32660, comment 5


Ignore:
Timestamp:
Apr 18, 2021, 8:02:55 PM (4 years ago)
Author:
Simon Charette

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #32660, comment 5

    initial v1  
    11Your code will break as soon as fields are deferred which is something model deletion does to instantiate model instances while reducing memory and CPU usage during cascade deletion.
    22
    3 In other code your code breaks the `Bar.objects.defer('bar1)` pattern because accessing fields triggers loading which [https://docs.djangoproject.com/en/3.2/ref/models/instances/#customizing-model-loading is covered by the docs].
     3Your code breaks the `Bar.objects.defer('bar1)` pattern because accessing fields triggers loading which [https://docs.djangoproject.com/en/3.2/ref/models/instances/#customizing-model-loading is covered by the docs].
    44
    55This is detailed a bit in #31475 but I suggest you avoid overriding `__init__` and favour `from_db_value` and rely on `fields` instead of if you cannot do `self.__dict__.get('bar1')` to bypass deferred attributes descriptors.
Back to Top