From 769d7cce4aedfcbba59f1b68577225d07701c206 Mon Sep 17 00:00:00 2001 From: Nick Pope Date: Sat, 23 Jul 2022 13:31:35 +0100 Subject: Used AND, OR, XOR constants instead of hard-coded values. --- django/db/models/sql/compiler.py | 3 ++- django/db/models/sql/query.py | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'django/db/models/sql') diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py index 461e1ae156..cfac22a019 100644 --- a/django/db/models/sql/compiler.py +++ b/django/db/models/sql/compiler.py @@ -19,6 +19,7 @@ from django.db.models.sql.constants import ( SINGLE, ) from django.db.models.sql.query import Query, get_order_dir +from django.db.models.sql.where import AND from django.db.transaction import TransactionManagementError from django.utils.functional import cached_property from django.utils.hashable import make_hashable @@ -1435,7 +1436,7 @@ class SQLCompiler: for index, select_col in enumerate(self.query.select): lhs_sql, lhs_params = self.compile(select_col) rhs = "%s.%s" % (qn(alias), qn2(columns[index])) - self.query.where.add(RawSQL("%s = %s" % (lhs_sql, rhs), lhs_params), "AND") + self.query.where.add(RawSQL("%s = %s" % (lhs_sql, rhs), lhs_params), AND) sql, params = self.as_sql() return "EXISTS (%s)" % sql, params diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index cf7566d771..14ed0c0a63 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -2658,7 +2658,7 @@ class JoinPromoter: # to rel_a would remove a valid match from the query. So, we need # to promote any existing INNER to LOUTER (it is possible this # promotion in turn will be demoted later on). - if self.effective_connector == "OR" and votes < self.num_children: + if self.effective_connector == OR and votes < self.num_children: to_promote.add(table) # If connector is AND and there is a filter that can match only # when there is a joinable row, then use INNER. For example, in @@ -2670,8 +2670,8 @@ class JoinPromoter: # (rel_a__col__icontains=Alex | rel_a__col__icontains=Russell) # then if rel_a doesn't produce any rows, the whole condition # can't match. Hence we can safely use INNER join. - if self.effective_connector == "AND" or ( - self.effective_connector == "OR" and votes == self.num_children + if self.effective_connector == AND or ( + self.effective_connector == OR and votes == self.num_children ): to_demote.add(table) # Finally, what happens in cases where we have: -- cgit v1.3