Fixed #32951 -- Removed Query.where_class & co.
Unused since 3caf957ed5
.
This commit is contained in:
parent
012f38f959
commit
c35b81b864
|
@ -15,6 +15,7 @@ from django.db.models.fields.related import (
|
|||
)
|
||||
from django.db.models.query_utils import PathInfo
|
||||
from django.db.models.sql import AND
|
||||
from django.db.models.sql.where import WhereNode
|
||||
from django.utils.functional import cached_property
|
||||
|
||||
|
||||
|
@ -466,11 +467,11 @@ class GenericRelation(ForeignObject):
|
|||
return ContentType.objects.get_for_model(self.model,
|
||||
for_concrete_model=self.for_concrete_model)
|
||||
|
||||
def get_extra_restriction(self, where_class, alias, remote_alias):
|
||||
def get_extra_restriction(self, alias, remote_alias):
|
||||
field = self.remote_field.model._meta.get_field(self.content_type_field_name)
|
||||
contenttype_pk = self.get_content_type().pk
|
||||
lookup = field.get_lookup('exact')(field.get_col(remote_alias), contenttype_pk)
|
||||
return where_class([lookup], connector=AND)
|
||||
return WhereNode([lookup], connector=AND)
|
||||
|
||||
def bulk_related_objects(self, objs, using=DEFAULT_DB_ALIAS):
|
||||
"""
|
||||
|
|
|
@ -711,7 +711,7 @@ class ForeignObject(RelatedField):
|
|||
"""
|
||||
return {}
|
||||
|
||||
def get_extra_restriction(self, where_class, alias, related_alias):
|
||||
def get_extra_restriction(self, alias, related_alias):
|
||||
"""
|
||||
Return a pair condition used for joining and subquery pushdown. The
|
||||
condition is something that responds to as_sql(compiler, connection)
|
||||
|
|
|
@ -164,8 +164,8 @@ class ForeignObjectRel(FieldCacheMixin):
|
|||
def get_joining_columns(self):
|
||||
return self.field.get_reverse_joining_columns()
|
||||
|
||||
def get_extra_restriction(self, where_class, alias, related_alias):
|
||||
return self.field.get_extra_restriction(where_class, related_alias, alias)
|
||||
def get_extra_restriction(self, alias, related_alias):
|
||||
return self.field.get_extra_restriction(related_alias, alias)
|
||||
|
||||
def set_field_name(self):
|
||||
"""
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -504,6 +504,11 @@ Miscellaneous
|
|||
individual nodes to a string. ``Node.render()`` should always return a string
|
||||
as documented.
|
||||
|
||||
* The ``where_class`` property of ``django.db.models.sql.query.Query`` and the
|
||||
``where_class`` argument to the private ``get_extra_restriction()`` method of
|
||||
``ForeignObject`` and ``ForeignObjectRel`` are removed. If needed, initialize
|
||||
``django.db.models.sql.where.WhereNode`` instead.
|
||||
|
||||
.. _deprecated-features-4.0:
|
||||
|
||||
Features deprecated in 4.0
|
||||
|
|
|
@ -32,7 +32,7 @@ class ActiveTranslationField(models.ForeignObject):
|
|||
"""
|
||||
requires_unique_target = False
|
||||
|
||||
def get_extra_restriction(self, where_class, alias, related_alias):
|
||||
def get_extra_restriction(self, alias, related_alias):
|
||||
return ColConstraint(alias, 'lang', get_language())
|
||||
|
||||
def get_extra_descriptor_filter(self, instance):
|
||||
|
|
|
@ -43,7 +43,7 @@ class StartsWithRelation(models.ForeignObject):
|
|||
"""
|
||||
return self.remote_field
|
||||
|
||||
def get_extra_restriction(self, where_class, alias, related_alias):
|
||||
def get_extra_restriction(self, alias, related_alias):
|
||||
to_field = self.remote_field.model._meta.get_field(self.to_fields[0])
|
||||
from_field = self.model._meta.get_field(self.from_fields[0])
|
||||
return StartsWith(to_field.get_col(alias), from_field.get_col(related_alias))
|
||||
|
@ -87,7 +87,7 @@ class BrokenContainsRelation(StartsWithRelation):
|
|||
This model is designed to yield no join conditions and
|
||||
raise an exception in ``Join.as_sql()``.
|
||||
"""
|
||||
def get_extra_restriction(self, where_class, alias, related_alias):
|
||||
def get_extra_restriction(self, alias, related_alias):
|
||||
return None
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue