Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Retrier and Catcher passed to constructor for Task, Parallel and Map states are not added to the state's Retriers and Catchers #169

Merged
merged 7 commits into from
Oct 7, 2021

Conversation

ca-nguyen
Copy link
Contributor

@ca-nguyen ca-nguyen commented Sep 23, 2021

Description

This will allow retry and catch blocks to be added directly from the constructor.

Fixes #115

Why is the change necessary?

Currently, retry and catch blocks passed to Task, Parallel and Map State constructors are not added to those state's Retriers and Catchers. With this change, it will possible do so.

Per the ASL documentation, Retry and Catch fields are arrays that contain Retriers and Catchers (see Task ASL doc for ex). This PR makes it possible to use lists or Retry/Catch objects in the constructor for retry and catch constructor arguments.

Solution

In the constructor, when retry/catch is not None, add it to the state's retries/catches.
This change is done for the 3 States that support Retry and Catch blocks: Task, Parallel and Map.

Testing

  • Added unit and integ tests
  • Manual testing

Action Items

TODO in a separate PR:

  • Update CONTRIBUTING guide in the testing section to use descriptive method names following the test_<unit_under_test>_<state_or_input_under_test>_<expectation> naming convention

Pull Request Checklist

Please check all boxes (including N/A items)

Testing

  • Unit tests added
  • integration test added

Documentation

  • docs: All relevant docs updated
  • docstrings: All public APIs documented

Title and description

  • Change type: Title is prefixed with change type: and follows conventional commits
  • References: Indicate issues fixed via: Fixes #xxx

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license.

Copy link
Contributor

@shivlaks shivlaks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great job!

couple of small general things

  • this is a fix... the discarding of user provided parameters in constructor is a bug that we are addressing rather than a feature.
  • let's tighten up the description to also include that this is for the Task, Parallel, and Map states. This is covered in the subsequent section but I think it belongs in the title
  • "Manual Testing" - this should detail what manual testing we performed. Another contributor should be able to read your description and perform the same manual test. It's both a teaching tool as well as a valuable artifact for posterity.

src/stepfunctions/steps/states.py Show resolved Hide resolved
tests/unit/test_steps.py Outdated Show resolved Hide resolved
tests/unit/test_steps.py Outdated Show resolved Hide resolved
tests/unit/test_steps.py Outdated Show resolved Hide resolved
tests/integ/test_state_machine_definition.py Outdated Show resolved Hide resolved
tests/integ/test_state_machine_definition.py Outdated Show resolved Hide resolved
tests/unit/test_steps.py Outdated Show resolved Hide resolved
src/stepfunctions/steps/states.py Outdated Show resolved Hide resolved
@ca-nguyen ca-nguyen changed the title feat: Add retry and catch to Retriers and Catchers when passed to constructor fix: Retrier and Catcher passed to constructor for Task, Parallel and Map states are not added to the state's Retriers and Catchers Oct 7, 2021
wong-a
wong-a previously approved these changes Oct 7, 2021
Copy link
Contributor

@wong-a wong-a left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM besides Shiv's comment on the integ test.

(CATCH, EXPECTED_CATCH),
(CATCHES, EXPECTED_CATCHES)
])
def test_parallel_state_constructor_with_catch_adds_catcher_to_catchers(catch, expected_catch):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment (non-blocking): This reads a lot better than before. I still don't think each test case needs to be parameterized at all, but that's nit picking/preference at this point.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed. im of the same opinion - it's a lot easier to understand what a test is doing.
verbosity in tests like these does more good than harm

tests/integ/test_state_machine_definition.py Show resolved Hide resolved
tests/integ/test_state_machine_definition.py Outdated Show resolved Hide resolved
Copy link
Contributor

@wong-a wong-a left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@StepFunctions-Bot
Copy link
Contributor

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-sEHrOdk7acJc
  • Commit ID: cd1fc9e
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

(CATCH, EXPECTED_CATCH),
(CATCHES, EXPECTED_CATCHES)
])
def test_parallel_state_constructor_with_catch_adds_catcher_to_catchers(catch, expected_catch):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed. im of the same opinion - it's a lot easier to understand what a test is doing.
verbosity in tests like these does more good than harm

interval_seconds = 1
max_attempts = 2
backoff_rate = 2
task_resource = f"arn:{get_aws_partition()}:states:::sagemaker:createTrainingJob.sync"

# change the parameters to cause task state to fail
# Provide invalid TrainingImage to cause States.TaskFailed error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you, it's a lot less mysterious what we're trying to do now

@ca-nguyen ca-nguyen merged commit 7f223e8 into aws:main Oct 7, 2021
@ca-nguyen ca-nguyen deleted the fix-retry-in-task-constructor branch October 27, 2021 01:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't serialize graphs using Retry
4 participants