Skip to content

Commit 662ead6

Browse files
andydouglas-exsshunjd
authored andcommitted
StepInput placeholder without key should resolve to $ (aws#7)
* Fixed the placeholder issue when passing the entire step output from previous step to the next step as the input.
1 parent f1bf880 commit 662ead6

File tree

4 files changed

+26
-14
lines changed

4 files changed

+26
-14
lines changed

src/stepfunctions/inputs/placeholders.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ def contains(self, placeholder):
132132
return True
133133
return False
134134

135+
def __contains__(self, placeholder):
136+
"""
137+
Containment check operator for placeholder variables.
138+
"""
139+
return self.contains(placeholder)
140+
135141
def validate(self, input):
136142
"""
137143
Validate a specified input against the placeholder collection schema.

src/stepfunctions/steps/states.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -701,8 +701,9 @@ def visit(self, state):
701701

702702
def _validate_next_step_params(self, params, step_output):
703703
for k, v in params.items():
704-
if isinstance(v, StepInput) and not step_output.contains(v):
705-
return False, k
704+
if isinstance(v, StepInput):
705+
if v is not step_output and not step_output.contains(v):
706+
return False, k
706707
elif isinstance(v, dict):
707708
valid, invalid_param_name = self._validate_next_step_params(v, step_output)
708709
if not valid:

tests/unit/test_placeholders_with_steps.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,21 @@ def test_workflow_input_placeholder():
2424
state_id='StateOne',
2525
parameters={
2626
'ParamA': 'SampleValueA',
27-
'ParamB': workflow_input['Key01'],
28-
'ParamC': workflow_input['Key02']['Key03'],
29-
'ParamD': workflow_input['Key01']['Key03'],
27+
'ParamB': workflow_input,
28+
'ParamC': workflow_input['Key01'],
29+
'ParamD': workflow_input['Key02']['Key03'],
30+
'ParamE': workflow_input['Key01']['Key03'],
3031
}
3132
)
3233

3334
expected_repr = {
3435
"Type": "Pass",
3536
"Parameters": {
3637
"ParamA": "SampleValueA",
37-
"ParamB.$": "$$.Execution.Input['Key01']",
38-
"ParamC.$": "$$.Execution.Input['Key02']['Key03']",
39-
"ParamD.$": "$$.Execution.Input['Key01']['Key03']"
38+
"ParamB.$": "$$.Execution.Input",
39+
"ParamC.$": "$$.Execution.Input['Key01']",
40+
"ParamD.$": "$$.Execution.Input['Key02']['Key03']",
41+
"ParamE.$": "$$.Execution.Input['Key01']['Key03']"
4042
},
4143
"End": True
4244
}
@@ -52,16 +54,18 @@ def test_step_input_placeholder():
5254
test_step_02 = Pass(
5355
state_id='StateTwo',
5456
parameters={
55-
'ParamA': test_step_01.output()["Response"]["Key02"],
56-
"ParamB": "SampleValueB"
57+
'ParamA': test_step_01.output(),
58+
'ParamB': test_step_01.output()["Response"]["Key02"],
59+
"ParamC": "SampleValueC"
5760
}
5861
)
5962

6063
expected_repr = {
6164
"Type": "Pass",
6265
"Parameters": {
63-
"ParamA.$": "$['Response']['Key02']",
64-
"ParamB": "SampleValueB"
66+
"ParamA.$": "$",
67+
"ParamB.$": "$['Response']['Key02']",
68+
"ParamC": "SampleValueC"
6569
},
6670
"End": True
6771
}
@@ -382,4 +386,4 @@ def test_schema_validation_for_step_input():
382386
'ParamA': test_step_01.output()["Response"].get("Key01", float),
383387
"ParamB": "SampleValueB"
384388
}
385-
)
389+
)

tests/unit/test_placeholders_with_workflows.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ def workflow(client):
5252
parameters={
5353
'ParamG': "SampleValueG",
5454
"ParamF": execution_input["Key06"],
55-
"ParamH": "SampleValueH"
55+
"ParamH": "SampleValueH",
56+
"ParamI": test_step_02.output()
5657
}
5758
)
5859

0 commit comments

Comments
 (0)