Refs #33766 -- Removed sql.Query.build_filtered_relation_q().

It was a copy of sql.Query._add_q that avoided JOIN updates.
This commit is contained in:
Simon Charette 2023-04-21 23:10:15 -04:00 committed by Mariusz Felisiak
parent 1a13161eab
commit 83c9765f45
2 changed files with 15 additions and 32 deletions

View File

@ -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):

View File

@ -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))