summaryrefslogtreecommitdiff
path: root/django/contrib/postgres/constraints.py
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2022-08-11 06:54:38 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-08-11 09:53:10 +0200
commit8533a6af8d937d487dd4a9f5c40ac98e111915a8 (patch)
treefa701f0caa691c0dd7572d76e91a2a17be378aac /django/contrib/postgres/constraints.py
parentfc0942ada47c6ed9bbd25f8a1d721ae0e2859776 (diff)
downloaddjango-8533a6af8d937d487dd4a9f5c40ac98e111915a8.tar.gz
Optimized ExclusionConstraint.validate() a bit.
References to excluded fields are omitted in the replacement_map, so there is no need to replace references before checking for exclusions.
Diffstat (limited to 'django/contrib/postgres/constraints.py')
-rw-r--r--django/contrib/postgres/constraints.py15
1 files changed, 7 insertions, 8 deletions
diff --git a/django/contrib/postgres/constraints.py b/django/contrib/postgres/constraints.py
index f71a587430..c67292f9f0 100644
--- a/django/contrib/postgres/constraints.py
+++ b/django/contrib/postgres/constraints.py
@@ -202,16 +202,15 @@ class ExclusionConstraint(BaseConstraint):
for idx, (expression, operator) in enumerate(self.expressions):
if isinstance(expression, str):
expression = F(expression)
- if isinstance(expression, F):
- if exclude and expression.name in exclude:
- return
- rhs_expression = expression.replace_references(replacement_map)
- else:
- rhs_expression = expression.replace_references(replacement_map)
- if exclude:
- for expr in rhs_expression.flatten():
+ if exclude:
+ if isinstance(expression, F):
+ if expression.name in exclude:
+ return
+ else:
+ for expr in expression.flatten():
if isinstance(expr, F) and expr.name in exclude:
return
+ rhs_expression = expression.replace_references(replacement_map)
# Remove OpClass because it only has sense during the constraint
# creation.
if isinstance(expression, OpClass):