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.
* needs_better_patch: => 0
* needs_docs: => 0
* needs_tests: => 0
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/24090#comment:1>
Comment (by akaariai):
This ticket was fixed by b68212f539f206679580afbfd008e7d329c9cd31. I'm
adding a pull request for tests.
--
Ticket URL: <https://code.djangoproject.com/ticket/24090#comment:2>
Comment (by Tim Graham <timograham@…>):
In [changeset:"76ac07a90967acb0225d0a590164ae1b7ad0e6bd" 76ac07a9]:
{{{
#!CommitTicketReference repository=""
revision="76ac07a90967acb0225d0a590164ae1b7ad0e6bd"
Refs #24090 -- Added a test for multi-table inheritance + subqueries.
Ticket #24090 was already fixed by
b68212f539f206679580afbfd008e7d329c9cd31, this commit adds tests to
verify this is indeed the case.
Thanks to Beauhurst for commissioning the work on this ticket.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24090#comment:3>
* status: new => closed
* resolution: => fixed
--
Ticket URL: <https://code.djangoproject.com/ticket/24090#comment:4>