#27065: Deferred fields not passed to inherited models' __class__.__dict__ -------------------------------------+------------------------------------- Reporter: jarekwg | Owner: nobody Type: Bug | Status: closed Component: Database layer | Version: 1.10 (models, ORM) | Severity: Normal | Resolution: invalid Keywords: defer only | Triage Stage: inherited DeferredAttribute | Unreviewed Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+------------------------------------- Changes (by jarekwg):
* keywords: defer inherited => defer only inherited DeferredAttribute * status: new => closed * resolution: => invalid Comment: Thanks, I've verified it's definitely commit 7f51876f99851fdc3fef63aecdfbcffa199c26b9 that causes this change in behaviour. `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`. 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. So `deffered_field = instance.__class__.__dict__.get(field_name) # pre dj110` becomes `deferred_field = getattr(instance.__class__, field_name) # dj110+` 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. Closing. -- Ticket URL: <https://code.djangoproject.com/ticket/27065#comment:2> 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 unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/065.01406dc06a00edce73a8bff557b4862e%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.