#31115: ORM generates wrong alias for subquery -------------------------------------+------------------------------------- Reporter: Dmitriy Gunchenko | Owner: Simon | Charette Type: Bug | Status: assigned Component: Database layer | Version: 3.0 (models, ORM) | Severity: Release blocker | Resolution: Keywords: orm, alias | Triage Stage: Accepted Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+-------------------------------------
Comment (by Simon Charette): Looks like the `external_aliases` tweaks of 5a4d7285bd10bd40d9f7e574a7c421eb21094858 which will be part of Django 3.0.2 happened to address this issue or at least the following regression test which crashes on PostgreSQL without the test. {{{#!diff diff --git a/tests/aggregation/tests.py b/tests/aggregation/tests.py index 5ba2e180e0..4febf96d94 100644 --- a/tests/aggregation/tests.py +++ b/tests/aggregation/tests.py @@ -1190,3 +1190,15 @@ class AggregateTestCase(TestCase): contact_publisher__isnull=False, ).annotate(count=Count('authors')) self.assertSequenceEqual(books_qs, [book]) + + def test_nested_subquery_join_outerref(self): + list(Author.objects.annotate( + friends_book=Subquery(Book.objects.filter( + authors__in=Subquery( + Author.objects.filter( + id=OuterRef('authors__friends__id'), + ).values('pk') + ), + authors__friends__id=OuterRef('id'), + ).values('pk')) + )) }}} Dmitriy, could you form your issue is effectively addressed by the aforementioned patch? I guess we should polish the test and add it to the suite at an appropriate location given it has nothing to do with aggregation. Thoughts? -- Ticket URL: <https://code.djangoproject.com/ticket/31115#comment:3> 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 django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/064.1123a57e37045b991b342153a4efa1b7%40djangoproject.com.