[Django] #26959: AssertionError in query.py change_aliases

17 views
Skip to first unread message

Django

unread,
Jul 26, 2016, 7:37:28 PM7/26/16
to django-...@googlegroups.com
#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.

Django

unread,
Jul 26, 2016, 7:39:27 PM7/26/16
to django-...@googlegroups.com
#26959: AssertionError in query.py change_aliases
-------------------------------------+-------------------------------------

Reporter: brownan | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.9
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by brownan):

* 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>

Django

unread,
Jul 27, 2016, 4:47:54 PM7/27/16
to django-...@googlegroups.com
#26959: AssertionError in query.py change_aliases
-------------------------------------+-------------------------------------
Reporter: brownan | Owner: nobody
Type: Bug | Status: closed

Component: Database layer | Version: 1.9
(models, ORM) |
Severity: Normal | Resolution: duplicate
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* 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>

Reply all
Reply to author
Forward
0 new messages