#24090: ORM (still!) neglects to use aliases it has set up when certain multiple
subqueries are used AND multi table inheritance is in use
-------------------------------------+-------------------------------------
Reporter: ris | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.7
(models, ORM) | Keywords: orm subquery alias
Severity: Normal | multi table inheritance mth
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
This is following on from ticket #23605, which was successfully fixed but
didn't fix our specific test case.
This turns out to be because our test case also used multi table
inheritance.
So, details are basically the same as #23605, but using django 1.7.2 and
the test models.py is:
{{{
from django.db import models
class ModelAParent ( models.Model ):
pass
class ModelA ( ModelAParent ):
pass
class ModelB ( models.Model ):
modela_fk = models.ForeignKey ( ModelA )
modelc_fk = models.ForeignKey ( "ModelC" )
field_b0 = models.IntegerField ( null = True )
field_b1 = models.BooleanField ()
class ModelC ( models.Model ):
field_c0 = models.FloatField ()
}}}
The query is the same:
{{{
ModelA.objects.filter (
Q ( pk__in = ModelA.objects.filter ( Q ( modelb__field_b0__gte =
1000000 / F ( "modelb__modelc_fk__field_c0" ) )
& Q ( modelb__field_b1__exact = True )
& ~Q ( modelb__pk__in = ModelB.objects.filter (
~(
Q ( field_b1__exact = True )
& Q ( field_b0__gte = 1000000 / F ( "modelc_fk__field_c0"
) )
)
) )
).filter ( modelb__field_b1__exact = True )
) )
}}}
Used against postgres 9.1 generates the error:
{{{
ProgrammingError: invalid reference to FROM-clause entry for table
"dummy_modelb"
LINE 1: ...") AND U0."field_b0" IS NOT NULL)) AND V1."id" = (dummy_mode...
^
HINT: Perhaps you meant to reference the table alias "v1".
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24090>
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/046.e5fd6a832c8d8cf705a8abd62bebfb0b%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.