youtype / mypy_boto3_builder

Type annotations builder for boto3 compatible with VSCode, PyCharm, Emacs, Sublime Text, pyright and mypy.
https://youtype.github.io/mypy_boto3_builder/
MIT License
548 stars 37 forks source link

[stepfunctions] Results of DescribeExecution inaccurate for differ execution statuses #321

Open taesungh opened 6 hours ago

taesungh commented 6 hours ago

The response of DescribeExecution in AWS Step Functions can vary based on the status of the given execution.

The current output type DescribeExecutionOutputTypeDef (for SFN.Client.describe_execution) specifies all items as required which is partly contradictory.

DescribeExecutionOutputTypeDef = TypedDict(
    "DescribeExecutionOutputTypeDef",
    {
        "executionArn": str,
        "stateMachineArn": str,
        "name": str,
        "status": ExecutionStatusType,
        "startDate": datetime,
        "stopDate": datetime,
        "input": str,
        "inputDetails": CloudWatchEventsExecutionDataDetailsTypeDef,
        "output": str,
        "outputDetails": CloudWatchEventsExecutionDataDetailsTypeDef,
        "traceHeader": str,
        "mapRunArn": str,
        "error": str,
        "cause": str,
        "stateMachineVersionArn": str,
        "stateMachineAliasArn": str,
        "redriveCount": int,
        "redriveDate": datetime,
        "redriveStatus": ExecutionRedriveStatusType,
        "redriveStatusReason": str,
        "ResponseMetadata": ResponseMetadataTypeDef,
    },
)

Example query and potential responses

import boto3
sfn_client = boto3.client("stepfunctions")
history = sfn_client.describe_execution(executionArn="arn:...")
For status RUNNING
```python { "executionArn": "arn:...", "stateMachineArn": "arn:...", "name": "...", "status": "RUNNING", "startDate": datetime.datetime(...), "input": '{...}', "inputDetails": {"included": True}, "redriveCount": 0, "redriveStatus": "NOT_REDRIVABLE", "redriveStatusReason": "Execution is RUNNING and cannot be redriven", "ResponseMetadata": { ... }, } ```
For status SUCCEEDED
```python { "executionArn": "arn:...", "stateMachineArn": "arn:...", "name": "...", "status": "SUCCEEDED", "startDate": datetime.datetime(...), "stopDate": datetime.datetime(...), "input": '{...}', "inputDetails": {"included": True}, "output": '{...}', "outputDetails": {"included": True}, "redriveCount": 0, "redriveStatus": "NOT_REDRIVABLE", "redriveStatusReason": "Execution is SUCCEEDED and cannot be redriven", "ResponseMetadata": { ... }, } ```
For status FAILED
```python { "executionArn": "arn:...", "stateMachineArn": "arn:...", "name": "...", "status": "FAILED", "startDate": datetime.datetime(...), "stopDate": datetime.datetime(...), "input": '{...}', "inputDetails": {"included": True}, "traceHeader": "...", "error": "Error", "cause": "...", "redriveCount": 0, "redriveStatus": "REDRIVABLE", "ResponseMetadata": { ... }, } ```
For status TIMED_OUT
```python { "executionArn": "arn:...", "stateMachineArn": "arn:...", "name": "...", "status": "TIMED_OUT", "startDate": datetime.datetime(...), "stopDate": datetime.datetime(...), "input": '{...}', "inputDetails": {"included": True}, "traceHeader": "...", "redriveStatus": "NOT_REDRIVABLE", "redriveStatusReason": "Execution's redrivable period has ended", "ResponseMetadata": { ... }, } ```
For status ABORTED
```python { "executionArn": "arn:...", "stateMachineArn": "arn:...", "name": "...", "status": "ABORTED", "startDate": datetime.datetime(...), "stopDate": datetime.datetime(...), "input": '{...}', "inputDetails": {"included": True}, "traceHeader": "...", "redriveStatus": "REDRIVABLE", "ResponseMetadata": { ... }, } ```

And there is also status PENDING_REDRIVE for which I don't have an example.

Resolution

It would be great if this builder could produce a union of narrowed variants although it may be difficult to account for all possible scenarios. Otherwise, marking certain fields as NotRequired would suffice. Specifically, it appears stopDate, output, outputDetails, error, cause, traceHeader, and redriveStatusReason are all possibly not included in the response along with mapRunArn, redriveDate, stateMachineAliasArn, and stateMachineVersionArn.

Additional context

Referencing mypy-boto3-stepfunctions v1.35.46

vemel commented 5 hours ago

Hello!

Thank you for the report. Unfortunately, there is no way to check totality of output shapes. However, it is possible to override a type parsed from botocore shapes and provide a union of potential output TypedDicts.

You could help me by writing all possible DescribeExecution...OutputTypeDefs here in a comment. Let me know if you are interested in adding an override for SFN.Client.describe_execution return type as a PR.