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.
@@ -202,16 +202,15 @@ class ExclusionConstraint(BaseConstraint):
for idx, (expression, operator) in enumerate(self.expressions):
if isinstance(expression, str):
expression = F(expression)
+ if exclude:
if isinstance(expression, F):
- if exclude and expression.name in exclude:
+ if 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():
+ 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):
