Changes between Initial Version and Version 1 of Ticket #27065, comment 2
- Timestamp:
- Aug 16, 2016, 9:07:57 PM (8 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #27065, comment 2
initial v1 3 3 `DeferredAttribute` instances inherited from parent models can no longer be obtained through `instance.__class__.__dict__` because the class is [https://github.com/django/django/commit/7f51876f99851fdc3fef63aecdfbcffa199c26b9#diff-1e7fc0d7d1b36358e371fab97bd1ddb1L236 no longer dynamically created], but rather has the `DeferredAttribute` instances [https://github.com/django/django/commit/7f51876f99851fdc3fef63aecdfbcffa199c26b9#diff-bf776a3b8e5dbfac2432015825ef8afeR695 stapled on] with `setattr`. 4 4 5 However, thanks to [https://github.com/django/django/commit/7f51876f99851fdc3fef63aecdfbcffa199c26b9#diff-1e7fc0d7d1b36358e371fab97bd1ddb1R99 this change], a handle to the `DeferredAttribute` can be obtained by accessing the field directly from the instance's class, which looks considerably nicer and ''does'' pull through inherited fields.5 However, thanks to [https://github.com/django/django/commit/7f51876f99851fdc3fef63aecdfbcffa199c26b9#diff-1e7fc0d7d1b36358e371fab97bd1ddb1R99 this change], a handle to the `DeferredAttribute` descriptor can be obtained by accessing the field directly from the instance's class, which looks considerably nicer and ''does'' pull through inherited fields. 6 6 7 7 So 8 `def fered_field = instance.__class__.__dict__.get(field_name) # pre dj110`8 `deferred_field = instance.__class__.__dict__.get(field_name) # pre dj110` 9 9 becomes 10 10 `deferred_field = getattr(instance.__class__, field_name) # dj110+` 11 11 12 I guess it can't hurt mentioning this in the release notes, though at the same time I don't see particularly many projects that would need to handle the `DeferredAttribute s`directly. You're in a better position to make that call. At the very least this ticket can serve as an answer to people who google this problem.12 I guess it can't hurt mentioning this in the release notes, though at the same time I don't see particularly many projects that would need to handle the `DeferredAttribute` descriptors directly. You're in a better position to make that call. At the very least this ticket can serve as an answer to people who google this problem. 13 13 14 14 Closing.