Fixed #32944 -- Avoided unnecessary WhereNode.add() calls.
Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
This commit is contained in:
parent
ff661dbd50
commit
6a970a8b46
|
@ -14,6 +14,7 @@ from django.db.models.fields.related import (
|
|||
ReverseManyToOneDescriptor, lazy_related_operation,
|
||||
)
|
||||
from django.db.models.query_utils import PathInfo
|
||||
from django.db.models.sql import AND
|
||||
from django.utils.functional import cached_property
|
||||
|
||||
|
||||
|
@ -468,10 +469,8 @@ class GenericRelation(ForeignObject):
|
|||
def get_extra_restriction(self, where_class, alias, remote_alias):
|
||||
field = self.remote_field.model._meta.get_field(self.content_type_field_name)
|
||||
contenttype_pk = self.get_content_type().pk
|
||||
cond = where_class()
|
||||
lookup = field.get_lookup('exact')(field.get_col(remote_alias), contenttype_pk)
|
||||
cond.add(lookup, 'AND')
|
||||
return cond
|
||||
return where_class([lookup], connector=AND)
|
||||
|
||||
def bulk_related_objects(self, objs, using=DEFAULT_DB_ALIAS):
|
||||
"""
|
||||
|
|
|
@ -1265,9 +1265,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)
|
||||
clause = self.where_class()
|
||||
clause.add(condition, AND)
|
||||
return clause, []
|
||||
return self.where_class([condition], connector=AND), []
|
||||
arg, value = filter_expr
|
||||
if not arg:
|
||||
raise FieldError("Cannot parse keyword query %r" % arg)
|
||||
|
@ -1286,11 +1284,9 @@ class Query(BaseExpression):
|
|||
if check_filterable:
|
||||
self.check_filterable(value)
|
||||
|
||||
clause = self.where_class()
|
||||
if reffed_expression:
|
||||
condition = self.build_lookup(lookups, reffed_expression, value)
|
||||
clause.add(condition, AND)
|
||||
return clause, []
|
||||
return self.where_class([condition], connector=AND), []
|
||||
|
||||
opts = self.get_meta()
|
||||
alias = self.get_initial_alias()
|
||||
|
@ -1333,7 +1329,7 @@ class Query(BaseExpression):
|
|||
|
||||
condition = self.build_lookup(lookups, col, value)
|
||||
lookup_type = condition.lookup_name
|
||||
clause.add(condition, AND)
|
||||
clause = self.where_class([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:
|
||||
|
|
Loading…
Reference in New Issue