From 62347208bb0cef6990699d7373fa06e2e12ead07 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Thu, 20 Aug 2015 12:46:14 -0400 Subject: [1.8.x] Fixed #24525 -- Fixed AssertionError in some complex queries. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thanks Anssi Kääriäinen for providing the solution. Backport of 2dc9ec5616a942de3a0886a707f93988f56dd594 from master --- django/db/models/sql/query.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'django') diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index 7a0fe8f892..40b6cc57a1 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -539,7 +539,8 @@ class Query(object): # distinct joins for the same connection in rhs query, then the # combined query must have two joins, too. reuse.discard(new_alias) - change_map[alias] = new_alias + if alias != new_alias: + change_map[alias] = new_alias if not rhs.alias_refcount[alias]: # The alias was unused in the rhs query. Unref it so that it # will be unused in the new query, too. We have to add and -- cgit v1.3