Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Removed join() promote kwarg

The join promote=True was over-aggressive in select_related handling.
After that was removed, the only other user was query.combine(). That
use case is very easy to handle locally, so there is no more need for
the join(promote=True) flag.

Refs #19849.
  • Loading branch information...
commit edf93127bf2f9dc35b45cdea5d39a1b417ab1638 1 parent 3fef304
Anssi Kääriäinen authored
4  django/db/models/sql/compiler.py
@@ -620,7 +620,7 @@ def fill_related_selections(self, opts=None, root_alias=None, cur_depth=1,
620 620
 
621 621
             alias = self.query.join((alias, table, f.column,
622 622
                     f.rel.get_related_field().column),
623  
-                    promote=promote, join_field=f)
  623
+                    outer_if_first=promote, join_field=f)
624 624
             columns, aliases = self.get_default_columns(start_alias=alias,
625 625
                     opts=f.rel.to._meta, as_pairs=True)
626 626
             self.query.related_select_cols.extend(
@@ -648,7 +648,7 @@ def fill_related_selections(self, opts=None, root_alias=None, cur_depth=1,
648 648
                 table = model._meta.db_table
649 649
                 alias = self.query.join(
650 650
                     (alias, table, f.rel.get_related_field().column, f.column),
651  
-                    promote=True, join_field=f
  651
+                    outer_if_first=True, join_field=f
652 652
                 )
653 653
                 from_parent = (opts.model if issubclass(model, opts.model)
654 654
                                else None)
25  django/db/models/sql/query.py
@@ -507,9 +507,11 @@ def combine(self, rhs, connector):
507 507
             # updated alias.
508 508
             lhs = change_map.get(lhs, lhs)
509 509
             new_alias = self.join(
510  
-                (lhs, table, lhs_col, col), reuse=reuse, promote=promote,
  510
+                (lhs, table, lhs_col, col), reuse=reuse,
511 511
                 outer_if_first=not conjunction, nullable=nullable,
512 512
                 join_field=join_field)
  513
+            if promote:
  514
+                self.promote_joins([new_alias])
513 515
             # We can't reuse the same join again in the query. If we have two
514 516
             # distinct joins for the same connection in rhs query, then the
515 517
             # combined query must have two joins, too.
@@ -914,8 +916,8 @@ def count_active_tables(self):
914 916
         """
915 917
         return len([1 for count in self.alias_refcount.values() if count])
916 918
 
917  
-    def join(self, connection, reuse=None, promote=False,
918  
-             outer_if_first=False, nullable=False, join_field=None):
  919
+    def join(self, connection, reuse=None, outer_if_first=False,
  920
+             nullable=False, join_field=None):
919 921
         """
920 922
         Returns an alias for the join in 'connection', either reusing an
921 923
         existing alias for that join or creating a new one. 'connection' is a
@@ -929,14 +931,8 @@ def join(self, connection, reuse=None, promote=False,
929 931
         (matching the connection) are reusable, or it can be a set containing
930 932
         the aliases that can be reused.
931 933
 
932  
-        If 'promote' is True, the join type for the alias will be LOUTER (if
933  
-        the alias previously existed, the join type will be promoted from INNER
934  
-        to LOUTER, if necessary).
935  
-
936 934
         If 'outer_if_first' is True and a new join is created, it will have the
937  
-        LOUTER join type. Used for example when adding ORed filters, where we
938  
-        want to use LOUTER joins except if some other join already restricts
939  
-        the join to INNER join.
  935
+        LOUTER join type.
940 936
 
941 937
         A join is always created as LOUTER if the lhs alias is LOUTER to make
942 938
         sure we do not generate chains like t1 LOUTER t2 INNER t3.
@@ -961,8 +957,6 @@ def join(self, connection, reuse=None, promote=False,
961 957
                 # join_field used for the under work join.
962 958
                 continue
963 959
             self.ref_alias(alias)
964  
-            if promote or (lhs and self.alias_map[lhs].join_type == self.LOUTER):
965  
-                self.promote_joins([alias])
966 960
             return alias
967 961
 
968 962
         # No reuse is possible, so we need a new alias.
@@ -971,10 +965,9 @@ def join(self, connection, reuse=None, promote=False,
971 965
             # Not all tables need to be joined to anything. No join type
972 966
             # means the later columns are ignored.
973 967
             join_type = None
974  
-        elif (promote or outer_if_first
975  
-              or self.alias_map[lhs].join_type == self.LOUTER):
976  
-            # We need to use LOUTER join if asked by promote or outer_if_first,
977  
-            # or if the LHS table is left-joined in the query.
  968
+        elif outer_if_first or self.alias_map[lhs].join_type == self.LOUTER:
  969
+            # We need to use LOUTER join if asked by outer_if_first or if the
  970
+            # LHS table is left-joined in the query.
978 971
             join_type = self.LOUTER
979 972
         else:
980 973
             join_type = self.INNER
23  tests/regressiontests/select_related_regress/tests.py
@@ -139,3 +139,26 @@ def test_regression_12851(self):

0 notes on commit edf9312

Please sign in to comment.
Something went wrong with that request. Please try again.