Changes between Initial Version and Version 1 of Ticket #27065, comment 2


Ignore:
Timestamp:
08/16/2016 09:07:57 PM (3 years ago)
Author:
Jarek Glowacki
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #27065, comment 2

    initial v1  
    33`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`.
    44
    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.
     5However, 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.
    66
    77So
    8 `deffered_field = instance.__class__.__dict__.get(field_name)  # pre dj110`
     8`deferred_field = instance.__class__.__dict__.get(field_name)  # pre dj110`
    99becomes
    1010`deferred_field = getattr(instance.__class__, field_name)  # dj110+`
    1111
    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 `DeferredAttributes` 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.
     12I 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.
    1313
    1414Closing.
Back to Top