Opened 10 years ago
Closed 9 years ago
#24090 closed Bug (fixed)
ORM (still!) neglects to use aliases it has set up when certain multiple subqueries are used AND multi table inheritance is in use
Reported by: | ris | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.7 |
Severity: | Normal | Keywords: | orm subquery alias multi table inheritance mth |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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".
Change History (4)
comment:1 by , 10 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 9 years ago
comment:4 by , 9 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
This ticket was fixed by b68212f539f206679580afbfd008e7d329c9cd31. I'm adding a pull request for tests.