diff options
| author | Nick Pope <nick@nickpope.me.uk> | 2021-07-20 20:38:17 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-07-22 08:49:20 +0200 |
| commit | c35b81b864ffa84751bac7d73046840f576491f9 (patch) | |
| tree | 2cabe599d59584591e90e55f06ce6bfd66978348 /django/db/models/sql | |
| parent | 012f38f9594b35743e9ab231757b7b62db638323 (diff) | |
Fixed #32951 -- Removed Query.where_class & co.
Unused since 3caf957ed5eaa831a485abcb89f27266dbf3e82b.
Diffstat (limited to 'django/db/models/sql')
| -rw-r--r-- | django/db/models/sql/compiler.py | 3 | ||||
| -rw-r--r-- | django/db/models/sql/datastructures.py | 3 | ||||
| -rw-r--r-- | django/db/models/sql/query.py | 22 | ||||
| -rw-r--r-- | django/db/models/sql/subqueries.py | 4 |
4 files changed, 15 insertions, 17 deletions
diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py index 4413b00825..36eee4b2a7 100644 --- a/django/db/models/sql/compiler.py +++ b/django/db/models/sql/compiler.py @@ -1504,7 +1504,6 @@ class SQLDeleteCompiler(SQLCompiler): pk.get_col(self.query.get_initial_alias()) ] outerq = Query(self.query.model) - outerq.where = self.query.where_class() if not self.connection.features.update_can_self_select: # Force the materialization of the inner query to allow reference # to the target table on MySQL. @@ -1626,7 +1625,7 @@ class SQLUpdateCompiler(SQLCompiler): # Now we adjust the current query: reset the where clause and get rid # of all the tables we don't need (since they're in the sub-select). - self.query.where = self.query.where_class() + self.query.clear_where() if self.query.related_updates or must_pre_select: # Either we're using the idents in multiple update queries (so # don't want them to change), or the db backend doesn't support diff --git a/django/db/models/sql/datastructures.py b/django/db/models/sql/datastructures.py index 85278cd8d3..e08b570350 100644 --- a/django/db/models/sql/datastructures.py +++ b/django/db/models/sql/datastructures.py @@ -78,8 +78,7 @@ class Join: # Add a single condition inside parentheses for whatever # get_extra_restriction() returns. - extra_cond = self.join_field.get_extra_restriction( - compiler.query.where_class, self.table_alias, self.parent_alias) + extra_cond = self.join_field.get_extra_restriction(self.table_alias, self.parent_alias) if extra_cond: extra_sql, extra_params = compiler.compile(extra_cond) join_conditions.append('(%s)' % extra_sql) diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index af5f684943..8ecac4a3b7 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -144,7 +144,7 @@ class Query(BaseExpression): compiler = 'SQLCompiler' - def __init__(self, model, where=WhereNode, alias_cols=True): + def __init__(self, model, alias_cols=True): self.model = model self.alias_refcount = {} # alias_map is the most important data structure regarding joins. @@ -175,8 +175,7 @@ class Query(BaseExpression): # clause to contain other than default fields (values(), subqueries...) # Note that annotations go to annotations dictionary. self.select = () - self.where = where() - self.where_class = where + self.where = WhereNode() # The group_by attribute can have one of the following forms: # - None: no group by at all in the query # - A tuple of expressions: group by (at least) those expressions. @@ -1265,7 +1264,7 @@ class Query(BaseExpression): condition = filter_expr.resolve_expression(self, allow_joins=allow_joins) if not isinstance(condition, Lookup): condition = self.build_lookup(['exact'], condition, True) - return self.where_class([condition], connector=AND), [] + return WhereNode([condition], connector=AND), [] arg, value = filter_expr if not arg: raise FieldError("Cannot parse keyword query %r" % arg) @@ -1286,7 +1285,7 @@ class Query(BaseExpression): if reffed_expression: condition = self.build_lookup(lookups, reffed_expression, value) - return self.where_class([condition], connector=AND), [] + return WhereNode([condition], connector=AND), [] opts = self.get_meta() alias = self.get_initial_alias() @@ -1329,7 +1328,7 @@ class Query(BaseExpression): condition = self.build_lookup(lookups, col, value) lookup_type = condition.lookup_name - clause = self.where_class([condition], connector=AND) + clause = WhereNode([condition], connector=AND) require_outer = lookup_type == 'isnull' and condition.rhs is True and not current_negated if current_negated and (lookup_type != 'isnull' or condition.rhs is False) and condition.rhs is not None: @@ -1381,6 +1380,9 @@ class Query(BaseExpression): def build_where(self, filter_expr): return self.build_filter(filter_expr, allow_joins=False)[0] + def clear_where(self): + self.where = WhereNode() + def _add_q(self, q_object, used_aliases, branch_negated=False, current_negated=False, allow_joins=True, split_subq=True, check_filterable=True): @@ -1388,8 +1390,7 @@ class Query(BaseExpression): connector = q_object.connector current_negated = current_negated ^ q_object.negated branch_negated = branch_negated or q_object.negated - target_clause = self.where_class(connector=connector, - negated=q_object.negated) + target_clause = WhereNode(connector=connector, negated=q_object.negated) joinpromoter = JoinPromoter(q_object.connector, len(q_object.children), current_negated) for child in q_object.children: child_clause, needed_inner = self.build_filter( @@ -1408,7 +1409,7 @@ class Query(BaseExpression): connector = q_object.connector current_negated ^= q_object.negated branch_negated = branch_negated or q_object.negated - target_clause = self.where_class(connector=connector, negated=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( @@ -2301,8 +2302,7 @@ class Query(BaseExpression): select_fields = [r[0] for r in join_field.related_fields] select_alias = lookup_tables[trimmed_paths + 1] self.unref_alias(lookup_tables[trimmed_paths]) - extra_restriction = join_field.get_extra_restriction( - self.where_class, None, lookup_tables[trimmed_paths + 1]) + extra_restriction = join_field.get_extra_restriction(None, lookup_tables[trimmed_paths + 1]) if extra_restriction: self.where.add(extra_restriction, AND) else: diff --git a/django/db/models/sql/subqueries.py b/django/db/models/sql/subqueries.py index e83112b046..904f1d096b 100644 --- a/django/db/models/sql/subqueries.py +++ b/django/db/models/sql/subqueries.py @@ -37,7 +37,7 @@ class DeleteQuery(Query): num_deleted = 0 field = self.get_meta().pk for offset in range(0, len(pk_list), GET_ITERATOR_CHUNK_SIZE): - self.where = self.where_class() + self.clear_where() self.add_q(Q( **{field.attname + '__in': pk_list[offset:offset + GET_ITERATOR_CHUNK_SIZE]})) num_deleted += self.do_query(self.get_meta().db_table, self.where, using=using) @@ -70,7 +70,7 @@ class UpdateQuery(Query): def update_batch(self, pk_list, values, using): self.add_update_values(values) for offset in range(0, len(pk_list), GET_ITERATOR_CHUNK_SIZE): - self.where = self.where_class() + self.clear_where() self.add_q(Q(pk__in=pk_list[offset: offset + GET_ITERATOR_CHUNK_SIZE])) self.get_compiler(using).execute_sql(NO_RESULTS) |
