Opened 11 years ago
Closed 11 years ago
#20874 closed Bug (fixed)
Nested subqueries have conflicting alias prefixes
Reported by: | Anssi Kääriäinen | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Currently the ORM has a way to bump table alias prefixes for subqueries. This means that for example alias T0 would be turned to U0. Unfortunately the current way doesn't work when nesting multiple queries, that is in cases like:
qs1 = MyModel.objects.all() qs2 = MyModel.objects.filter(pk__in=qs1) qs3 = MyModel.objects.filter(pk__in=qs2)
for qs2 the qs1 gets bumped to U-prefixes. But qs2 gets bumped *again* to U-prefixes in qs3. Luckily this doesn't usually matter that much in current Django, as for example "u0.id IN (SELECT u0.id FROM sometable u0) does work. Later on, if EXISTS queries are going to be more common this will become more important as "WHERE EXISTS (SELECT ... WHERE u0.id = u0.id) doesn't work at all.
Change History (2)
comment:1 by , 11 years ago
Has patch: | set |
---|---|
Triage Stage: | Unreviewed → Ready for checkin |
comment:2 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Patch available at https://github.com/akaariai/django/tree/ticket_20874
I think this one is ready for checkin, but as the fix is nontrivial I will leave this open for reviews.