summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2023-04-21 23:10:15 -0400
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-04-24 08:32:49 +0200
commit83c9765f45e4622e4a5af3adcd92263a28b13624 (patch)
tree5a04874efd06b5e6a12a5c95ef9c5e4bbc2300e5 /django
parent1a13161eab2d040990734f80b3eedea354f6a4ba (diff)
downloaddjango-83c9765f45e4622e4a5af3adcd92263a28b13624.tar.gz
Refs #33766 -- Removed sql.Query.build_filtered_relation_q().
It was a copy of sql.Query._add_q that avoided JOIN updates.
Diffstat (limited to 'django')
-rw-r--r--django/db/models/query_utils.py10
-rw-r--r--django/db/models/sql/query.py37
2 files changed, 15 insertions, 32 deletions
diff --git a/django/db/models/query_utils.py b/django/db/models/query_utils.py
index 52b472d252..78148f76b0 100644
--- a/django/db/models/query_utils.py
+++ b/django/db/models/query_utils.py
@@ -433,9 +433,13 @@ class FilteredRelation:
def resolve_expression(self, query, reuse, *args, **kwargs):
clone = self.clone()
- clone.resolved_condition = query.build_filtered_relation_q(
- self.condition, reuse=reuse
- )
+ clone.resolved_condition = query.build_filter(
+ self.condition,
+ can_reuse=reuse,
+ allow_joins=True,
+ split_subq=False,
+ update_join_types=False,
+ )[0]
return clone
def as_sql(self, compiler, connection):
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index 24e08ae6a6..c8f849daea 100644
--- a/django/db/models/sql/query.py
+++ b/django/db/models/sql/query.py
@@ -1347,6 +1347,7 @@ class Query(BaseExpression):
split_subq=True,
check_filterable=True,
summarize=False,
+ update_join_types=True,
):
"""
Build a WhereNode for a single filter clause but don't add it
@@ -1385,6 +1386,7 @@ class Query(BaseExpression):
split_subq=split_subq,
check_filterable=check_filterable,
summarize=summarize,
+ update_join_types=update_join_types,
)
if hasattr(filter_expr, "resolve_expression"):
if not getattr(filter_expr, "conditional", False):
@@ -1537,6 +1539,7 @@ class Query(BaseExpression):
split_subq=True,
check_filterable=True,
summarize=False,
+ update_join_types=True,
):
"""Add a Q-object to the current filter."""
connector = q_object.connector
@@ -1556,41 +1559,17 @@ class Query(BaseExpression):
split_subq=split_subq,
check_filterable=check_filterable,
summarize=summarize,
+ update_join_types=update_join_types,
)
joinpromoter.add_votes(needed_inner)
if child_clause:
target_clause.add(child_clause, connector)
- needed_inner = joinpromoter.update_join_types(self)
+ if update_join_types:
+ needed_inner = joinpromoter.update_join_types(self)
+ else:
+ needed_inner = []
return target_clause, needed_inner
- def build_filtered_relation_q(
- self, q_object, reuse, branch_negated=False, current_negated=False
- ):
- """Add a FilteredRelation object to the current filter."""
- connector = q_object.connector
- current_negated ^= q_object.negated
- branch_negated = branch_negated or q_object.negated
- target_clause = WhereNode(connector=connector, negated=q_object.negated)
- for child in q_object.children:
- if isinstance(child, Node):
- child_clause = self.build_filtered_relation_q(
- child,
- reuse=reuse,
- branch_negated=branch_negated,
- current_negated=current_negated,
- )
- else:
- child_clause, _ = self.build_filter(
- child,
- can_reuse=reuse,
- branch_negated=branch_negated,
- current_negated=current_negated,
- allow_joins=True,
- split_subq=False,
- )
- target_clause.add(child_clause, connector)
- return target_clause
-
def add_filtered_relation(self, filtered_relation, alias):
filtered_relation.alias = alias
lookups = dict(get_children_from_q(filtered_relation.condition))