#24762: Proxy models with children which inherit from the proxy cannot
select_related said children
----------------------------------------------+--------------------
     Reporter:  kezabelle                     |      Owner:  nobody
         Type:  Bug                           |     Status:  new
    Component:  Database layer (models, ORM)  |    Version:  master
     Severity:  Normal                        |   Keywords:
 Triage Stage:  Unreviewed                    |  Has patch:  0
Easy pickings:  0                             |      UI/UX:  0
----------------------------------------------+--------------------
 This has only been briefly checked on `1.7`, `1.8` and
 `django-1.9.dev20150506223347` (`master`), and appears to silently pass on
 1.6 (because `select_related` previously didn't raise errors)

 Given the following models:
 {{{
 class InheritanceProxyConcrete(models.Model):
     pass

 class InheritanceProxy(InheritanceProxyConcrete):
     class Meta:
         proxy = True

 class InheritanceProxyChild(InheritanceProxy):
     pass
 }}}
 I would expect to be able to do the following:
 {{{
 >>> InheritanceProxy.objects.select_related('inheritanceproxychild')
 [<InheritanceProxy: InheritanceProxy object>]
 # equating to something like
 SELECT "tests_inheritanceproxyconcrete"."id",
 "tests_inheritanceproxychild"."inheritanceproxyconcrete_ptr_id" FROM
 "tests_inheritanceproxyconcrete" LEFT OUTER JOIN
 "tests_inheritanceproxychild" ON ( "tests_inheritanceproxyconcrete"."id" =
 "tests_inheritanceproxychild"."inheritanceproxyconcrete_ptr_id" )
 }}}
 however, it transpires that it doesn't work:
 {{{
 >>>
 InheritanceProxyConcrete.objects.select_related('inheritanceproxychild')
 [<InheritanceProxyConcrete: InheritanceProxyConcrete object>]
 >>> InheritanceProxy.objects.select_related('inheritanceproxychild')
 FieldError: Invalid field name(s) given in select_related:
 'inheritanceproxychild'. Choices are: (none)
 >>> InheritanceProxy.objects.select_related('inheritanceproxychild_ptr')
 FieldError: Invalid field name(s) given in select_related:
 'inheritanceproxychild_ptr'. Choices are: (none)
 }}}

 Furthering the quirkiness of the problem:
 {{{
 >>> dir(InheritanceProxy)
 ['DoesNotExist', 'MultipleObjectsReturned', '__class__', ...
 'inheritanceproxychild', ...]
 >>> InheritanceProxy.inheritanceproxychild
 <django.db.models.fields.related.SingleRelatedObjectDescriptor object at
 0xBLAHBlAH>
 }}}
 I've not worked with proxies much, and certainly not recently, so there's
 a good probability I'm making assumptions about what functionality should
 be provided based on an incomplete understanding of their use cases.

 I've not tested explicit `OneToOnes`, `ForeignKeys`, `ManyToManys` or
 `prefetch_related`, so the possibility remains that it is only implicit
 parentage `OneToOnes` which are affected.

 This stems from a ticket downstream in [https://github.com/carljm/django-
 model-utils/issues/168 django-model-utils] regarding using a Proxy model
 as the parent for auto-downcasting model instances (using it's
 `InheritanceManager`)

--
Ticket URL: <https://code.djangoproject.com/ticket/24762>
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/052.290b1cf0771a2bce22c54cb80ccddc16%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to