#24525: AssertionError at `Query.change_aliases`
-------------------------------------+-------------------------------------
     Reporter:  coolRR               |                    Owner:  nobody
         Type:  Bug                  |                   Status:  closed
    Component:  Database layer       |                  Version:  1.7
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  needsinfo
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by kevmitch):

 In Django 1.8, with the models

 {{{
 #!python
 from django.db import models

 class Year(models.Model):
     date = models.DateField(auto_now_add=True)

 class Student(models.Model):
     year    = models.ForeignKey('Year')
     number  = models.PositiveIntegerField()
     courses = models.ManyToManyField('Course')

 class Course(models.Model):
     year       = models.ForeignKey('Year')
     department = models.CharField(max_length=4)
     number     = models.PositiveIntegerField()
 }}}

 the following

 {{{
 #!python
 course_instance.student_set.all() &
 year_instance.student_set.exclude(courses__in=[other_course_instance])
 }}}

 will raise
 {{{
 Traceback (most recent call last):
   File
 "/home/kevmitch/projects/apprentice/and_assertion_error/enrollment/tests.py",
 line 24, in test_and
     result = math101.student_set.all() &
 year.student_set.exclude(courses__in=[anth100])
   File
 "/home/kevmitch/projects/apprentice/apprentice/env/local/lib/python2.7
 /site-packages/django/db/models/query.py", line 211, in __and__
     combined.query.combine(other.query, sql.AND)
   File
 "/home/kevmitch/projects/apprentice/apprentice/env/local/lib/python2.7
 /site-packages/django/db/models/sql/query.py", line 556, in combine
     w.relabel_aliases(change_map)
   File
 "/home/kevmitch/projects/apprentice/apprentice/env/local/lib/python2.7
 /site-packages/django/db/models/sql/where.py", line 285, in
 relabel_aliases
     child.relabel_aliases(change_map)
   File
 "/home/kevmitch/projects/apprentice/apprentice/env/local/lib/python2.7
 /site-packages/django/db/models/sql/where.py", line 287, in
 relabel_aliases
     self.children[pos] = child.relabeled_clone(change_map)
   File
 "/home/kevmitch/projects/apprentice/apprentice/env/local/lib/python2.7
 /site-packages/django/db/models/lookups.py", line 185, in relabeled_clone
     new.rhs = new.rhs.relabeled_clone(relabels)
   File
 "/home/kevmitch/projects/apprentice/apprentice/env/local/lib/python2.7
 /site-packages/django/db/models/sql/query.py", line 329, in
 relabeled_clone
     clone.change_aliases(change_map)
   File
 "/home/kevmitch/projects/apprentice/apprentice/env/local/lib/python2.7
 /site-packages/django/db/models/sql/query.py", line 787, in change_aliases
     assert set(change_map.keys()).intersection(set(change_map.values()))
 == set()
 AssertionError
 }}}

 The tests of attached project demonstrates it in action.

 Essential elements for reproduction:

 * One of the querysets generated from related manager of the ManyToMany
 target
 * The other queryset is generated by exclude()ing on the ManyToManyField
 from the related manager of a "versioning" ForeignKey model

--
Ticket URL: <https://code.djangoproject.com/ticket/24525#comment:11>
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/064.80bde147d893142c071366766a4e6b73%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to