Anonymous committed e800169

queryset-refactor: For custom Q-like objects, pass in the used_aliases
parameter (see [7462]) from Query.add_q() to their add_to_query() method. This
provides custom objects with the same context as Q's.

  • Participants
  • Parent commits c0f3113
  • Branches queryset-refactor

Comments (0)

Files changed (1)

File django/db/models/sql/

         Can also be used to add anything that has an 'add_to_query()' method.
+        if used_aliases is None:
+            used_aliases = set()
         if hasattr(q_object, 'add_to_query'):
             # Complex custom objects are responsible for adding themselves.
-            q_object.add_to_query(self)
+            q_object.add_to_query(self, used_aliases)
         if self.where and q_object.connector != AND and len(q_object) > 1:
             subtree = False
         connector = AND
-        if used_aliases is None:
-            used_aliases = set()
         for child in q_object.children:
             if isinstance(child, Node):