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,
|
ReverseManyToOneDescriptor, lazy_related_operation,
|
||||||
)
|
)
|
||||||
from django.db.models.query_utils import PathInfo
|
from django.db.models.query_utils import PathInfo
|
||||||
|
from django.db.models.sql import AND
|
||||||
from django.utils.functional import cached_property
|
from django.utils.functional import cached_property
|
||||||
|
|
||||||
|
|
||||||
@ -468,10 +469,8 @@ class GenericRelation(ForeignObject):
|
|||||||
def get_extra_restriction(self, where_class, alias, remote_alias):
|
def get_extra_restriction(self, where_class, alias, remote_alias):
|
||||||
field = self.remote_field.model._meta.get_field(self.content_type_field_name)
|
field = self.remote_field.model._meta.get_field(self.content_type_field_name)
|
||||||
contenttype_pk = self.get_content_type().pk
|
contenttype_pk = self.get_content_type().pk
|
||||||
cond = where_class()
|
|
||||||
lookup = field.get_lookup('exact')(field.get_col(remote_alias), contenttype_pk)
|
lookup = field.get_lookup('exact')(field.get_col(remote_alias), contenttype_pk)
|
||||||
cond.add(lookup, 'AND')
|
return where_class([lookup], connector=AND)
|
||||||
return cond
|
|
||||||
|
|
||||||
def bulk_related_objects(self, objs, using=DEFAULT_DB_ALIAS):
|
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)
|
condition = filter_expr.resolve_expression(self, allow_joins=allow_joins)
|
||||||
if not isinstance(condition, Lookup):
|
if not isinstance(condition, Lookup):
|
||||||
condition = self.build_lookup(['exact'], condition, True)
|
condition = self.build_lookup(['exact'], condition, True)
|
||||||
clause = self.where_class()
|
return self.where_class([condition], connector=AND), []
|
||||||
clause.add(condition, AND)
|
|
||||||
return clause, []
|
|
||||||
arg, value = filter_expr
|
arg, value = filter_expr
|
||||||
if not arg:
|
if not arg:
|
||||||
raise FieldError("Cannot parse keyword query %r" % arg)
|
raise FieldError("Cannot parse keyword query %r" % arg)
|
||||||
@ -1286,11 +1284,9 @@ class Query(BaseExpression):
|
|||||||
if check_filterable:
|
if check_filterable:
|
||||||
self.check_filterable(value)
|
self.check_filterable(value)
|
||||||
|
|
||||||
clause = self.where_class()
|
|
||||||
if reffed_expression:
|
if reffed_expression:
|
||||||
condition = self.build_lookup(lookups, reffed_expression, value)
|
condition = self.build_lookup(lookups, reffed_expression, value)
|
||||||
clause.add(condition, AND)
|
return self.where_class([condition], connector=AND), []
|
||||||
return clause, []
|
|
||||||
|
|
||||||
opts = self.get_meta()
|
opts = self.get_meta()
|
||||||
alias = self.get_initial_alias()
|
alias = self.get_initial_alias()
|
||||||
@ -1333,7 +1329,7 @@ class Query(BaseExpression):
|
|||||||
|
|
||||||
condition = self.build_lookup(lookups, col, value)
|
condition = self.build_lookup(lookups, col, value)
|
||||||
lookup_type = condition.lookup_name
|
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
|
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:
|
if current_negated and (lookup_type != 'isnull' or condition.rhs is False) and condition.rhs is not None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user