Skip to content

Commit f2b47ab

Browse files
authored
fix: change ConditionNot incorrect property Expression to Condition (#4351)
1 parent 80b3e08 commit f2b47ab

File tree

5 files changed

+13
-12
lines changed

5 files changed

+13
-12
lines changed

src/sagemaker/local/pipeline.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ def _resolve_not_condition(self, not_condition: dict):
444444
True if given ConditionNot evaluated as true,
445445
False otherwise.
446446
"""
447-
return not self._resolve_condition(not_condition["Expression"])
447+
return not self._resolve_condition(not_condition["Condition"])
448448

449449
def _resolve_or_condition(self, or_condition: dict):
450450
"""Resolve given ConditionOr.

src/sagemaker/workflow/conditions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ def __init__(self, expression: Condition):
259259

260260
def to_request(self) -> RequestType:
261261
"""Get the request structure for workflow service calls."""
262-
return {"Type": self.condition_type.value, "Expression": self.expression.to_request()}
262+
return {"Type": self.condition_type.value, "Condition": self.expression.to_request()}
263263

264264
@property
265265
def _referenced_steps(self) -> List[str]:

tests/integ/sagemaker/workflow/test_fail_steps.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from tests.integ.sagemaker.workflow.helpers import wait_pipeline_execution
1818
from sagemaker import get_execution_role, utils
1919
from sagemaker.workflow.condition_step import ConditionStep
20-
from sagemaker.workflow.conditions import ConditionEquals
20+
from sagemaker.workflow.conditions import ConditionEquals, ConditionNot
2121
from sagemaker.workflow.fail_step import FailStep
2222

2323
from sagemaker.workflow.functions import Join
@@ -37,14 +37,15 @@ def pipeline_name():
3737

3838
def test_two_step_fail_pipeline_with_str_err_msg(sagemaker_session, role, pipeline_name):
3939
param = ParameterInteger(name="MyInt", default_value=2)
40-
cond = ConditionEquals(left=param, right=1)
40+
cond_equal = ConditionEquals(left=param, right=2)
41+
cond_not_equal = ConditionNot(cond_equal)
4142
step_fail = FailStep(
4243
name="FailStep",
4344
error_message="Failed due to hitting in else branch",
4445
)
4546
step_cond = ConditionStep(
4647
name="CondStep",
47-
conditions=[cond],
48+
conditions=[cond_not_equal],
4849
if_steps=[],
4950
else_steps=[step_fail],
5051
)

tests/unit/sagemaker/workflow/test_condition_step.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,15 @@ def test_pipeline_condition_step_interpolated(sagemaker_session):
202202
},
203203
{
204204
"Type": "Not",
205-
"Expression": {
205+
"Condition": {
206206
"Type": "Equals",
207207
"LeftValue": {"Get": "Parameters.MyInt1"},
208208
"RightValue": {"Get": "Parameters.MyInt2"},
209209
},
210210
},
211211
{
212212
"Type": "Not",
213-
"Expression": {
213+
"Condition": {
214214
"Type": "In",
215215
"QueryValue": {"Get": "Parameters.MyStr"},
216216
"Values": ["abc", "def"],
@@ -533,9 +533,9 @@ def func2():
533533
assert len(step_dsl["Arguments"]["Conditions"]) == 1
534534
condition_dsl = step_dsl["Arguments"]["Conditions"][0]
535535
assert condition_dsl["Type"] == "Not"
536-
cond_expr_dsl = condition_dsl["Expression"]
536+
cond_expr_dsl = condition_dsl["Condition"]
537537
assert cond_expr_dsl["Type"] == "Not"
538-
cond_inner_expr_dsl = cond_expr_dsl["Expression"]
538+
cond_inner_expr_dsl = cond_expr_dsl["Condition"]
539539
assert cond_inner_expr_dsl["Type"] == "Or"
540540
assert len(cond_inner_expr_dsl["Conditions"]) == 2
541541
assert cond_inner_expr_dsl["Conditions"][0]["LeftValue"] == _get_expected_jsonget_expr(
@@ -602,7 +602,7 @@ def func4():
602602
assert len(step_dsl["Arguments"]["Conditions"]) == 1
603603
condition_dsl = step_dsl["Arguments"]["Conditions"][0]
604604
assert condition_dsl["Type"] == "Not"
605-
cond_expr_dsl = condition_dsl["Expression"]
605+
cond_expr_dsl = condition_dsl["Condition"]
606606
assert cond_expr_dsl["Type"] == "In"
607607
assert cond_expr_dsl["QueryValue"] == _get_expected_jsonget_expr(
608608
step_name=step_output3._step.name, path="Result"

tests/unit/sagemaker/workflow/test_conditions.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def test_condition_not():
122122
cond_not = ConditionNot(expression=cond_eq)
123123
assert cond_not.to_request() == {
124124
"Type": "Not",
125-
"Expression": {
125+
"Condition": {
126126
"Type": "Equals",
127127
"LeftValue": param,
128128
"RightValue": "foo",
@@ -136,7 +136,7 @@ def test_condition_not_in():
136136
cond_not = ConditionNot(expression=cond_in)
137137
assert cond_not.to_request() == {
138138
"Type": "Not",
139-
"Expression": {
139+
"Condition": {
140140
"Type": "In",
141141
"QueryValue": param,
142142
"Values": ["abc", "def"],

0 commit comments

Comments
 (0)