I've tried on both Django 1.9.8 and 1.10rc1
Here's the backtrace:
{{{
Traceback (most recent call last):
File "/.../app/tests.py", line 32, in test_asserterror
return qs1 | qs2
File "/.../env/local/lib/python2.7/site-
packages/django/db/models/query.py", line 318, in __or__
combined.query.combine(other.query, sql.OR)
File "/.../env/local/lib/python2.7/site-
packages/django/db/models/sql/query.py", line 573, in combine
w.relabel_aliases(change_map)
File "/.../env/local/lib/python2.7/site-
packages/django/db/models/sql/where.py", line 129, in relabel_aliases
child.relabel_aliases(change_map)
File "/.../env/local/lib/python2.7/site-
packages/django/db/models/sql/where.py", line 131, in relabel_aliases
self.children[pos] = child.relabeled_clone(change_map)
File "/.../env/local/lib/python2.7/site-
packages/django/db/models/lookups.py", line 103, in relabeled_clone
new.rhs = new.rhs.relabeled_clone(relabels)
File "/.../env/local/lib/python2.7/site-
packages/django/db/models/sql/query.py", line 346, in relabeled_clone
clone.change_aliases(change_map)
File "/.../env/local/lib/python2.7/site-
packages/django/db/models/sql/query.py", line 793, in change_aliases
assert set(change_map.keys()).intersection(set(change_map.values()))
== set()
AssertionError
}}}
And I've managed to simplify down a test case the best I could.
models.py:
{{{#!python
class Group(models.Model):
pass
class User(models.Model):
groups = models.ManyToManyField(Group, related_name="members_of")
friends = models.ManyToManyField('self')
}}}
test case:
{{{#!python
g1 = models.Group.objects.create()
g2 = models.Group.objects.create()
g3 = models.Group.objects.create()
u1 = models.User.objects.create()
otherusers = models.User.objects.exclude(
pk=u1.pk
).exclude(
friends=u1
)
qs1 = otherusers.filter(
groups=g1
).filter(
groups=g2
)
qs2 = otherusers.filter(
groups=g1
).filter(
groups=g3
)
qs1 | qs2
}}}
Let me know if I can provide any other information that would be helpful.
Oddly enough in my app it only happens part of the time, seemingly at
random, but this test case seems to hit the assertion every time for me.
--
Ticket URL: <https://code.djangoproject.com/ticket/26959>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
I forgot to mention that I did see bug #24525, and this certainly seems
related, but I'm still hitting this error in the latest versions of Django
as stated above.
--
Ticket URL: <https://code.djangoproject.com/ticket/26959#comment:1>
* status: new => closed
* resolution: => duplicate
Old description:
New description:
models.py:
{{{#!python
class Group(models.Model):
pass
u1 = models.User.objects.create()
list(qs1 | qs2)
}}}
Let me know if I can provide any other information that would be helpful.
Oddly enough in my app it only happens part of the time, seemingly at
random, but this test case seems to hit the assertion every time for me.
--
Comment:
Looks like it's probably a duplicate of #26522.
--
Ticket URL: <https://code.djangoproject.com/ticket/26959#comment:2>