Changes between Initial Version and Version 1 of Ticket #32660, comment 5
- Timestamp:
- Apr 18, 2021, 8:02:55 PM (4 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #32660, comment 5
initial v1 1 1 Your 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. 2 2 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].3 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]. 4 4 5 5 This 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.