Skip to content

💫 Toolkit to help you get started with SDD or any other process!

fix(workflows): evaluate 'in'/'not in' safely on a non-iterable right operand (#3447) (#3468)

Noor ul ain73093954e283
diff --git a/tests/test_workflows.py b/tests/test_workflows.py
index d5a6d2697..d129257db 100644
--- a/tests/test_workflows.py
+++ b/tests/test_workflows.py
@@ -475,11 +475,11 @@ class TestExpressions:
# previous `right is not None` guard and mirrors _safe_compare, which
# already swallows TypeError for the ordering operators.
ctx = StepContext(inputs={"tag": "x", "count": 5, "ratio": 1.5, "flag": True})
- assert evaluate_expression("{{ inputs.tag in inputs.count }}", ctx) is False
- assert evaluate_expression("{{ inputs.tag not in inputs.count }}", ctx) is True
- assert evaluate_expression("{{ 'a' in inputs.ratio }}", ctx) is False
- assert evaluate_expression("{{ 'a' in inputs.flag }}", ctx) is False
- assert evaluate_expression("{{ inputs.tag in inputs.missing }}", ctx) is False
+ # `in` -> False and `not in` -> True for every non-iterable right
+ # operand (int, float, bool, None), so neither operator can drift.
+ for right in ("count", "ratio", "flag", "missing"):
+ assert evaluate_expression(f"{{{{ inputs.tag in inputs.{right} }}}}", ctx) is False
+ assert evaluate_expression(f"{{{{ inputs.tag not in inputs.{right} }}}}", ctx) is True
# A condition that would otherwise crash the run now evaluates cleanly.
assert evaluate_condition("{{ inputs.tag in inputs.count }}", ctx) is False