#26522: Non-determinstic crash in django.db.models.sql.Query.combine() -------------------------------------+------------------------------------- Reporter: Ole Laursen | Owner: nobody Type: Bug | Status: new Component: Database layer | Version: 1.9 (models, ORM) | Severity: Normal | Resolution: Keywords: | Triage Stage: Accepted Has patch: 1 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+------------------------------------- Changes (by Bo Marchman):
* has_patch: 0 => 1 Comment: PR at https://github.com/django/django/pull/8139 I ran into this bug yesterday and spent some time trying to figure out what's going on. It seems like the circular reference arises when `alias_map` is iterated in `Query.join` in order to find the next alias to reuse: {{{ reuse = [a for a, j in self.alias_map.items() if (reuse is None or a in reuse) and j == join] if reuse: self.ref_alias(reuse[0]) return reuse[0] }}} Because `alias_map` is a dict, the alias to reuse is chosen non- deterministically. Using an `OrderedDict` for `alias_map` solves this problem. It can also by solved by changing the reuse code to {{{ reuse = [a for a, j in self.alias_map.items() if (reuse is None or a in reuse) and j == join] if reuse: if join.table_alias in reuse: to_use = join.table_alias else: to_use = reuse[0] self.ref_alias(to_use) return to_use }}} But the `OrderedDict` seems cleaner to me. I don't understand much of the join internals here so I'd love to hear if someone has a better solution. -- Ticket URL: <https://code.djangoproject.com/ticket/26522#comment:6> 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 django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/068.4fec2e6b0f021e87bee03476454666a5%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.