#26959: AssertionError in query.py change_aliases
----------------------------------------------+--------------------
Reporter: brownan | Owner: nobody
Type: Bug | Status: new
Component: Database layer (models, ORM) | Version: 1.9
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+--------------------
I'm running into this AssertionError on a fairly complex query in my app,
involving ORing two querysets together.
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.
--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/050.d4c76282ee62e71fdf1f2588957fd70a%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.