This is an automated email from the ASF dual-hosted git repository.
onikolas pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 9c5908e050 `StepFunctionStartExecutionOperator`: get logs in case of
failure (#31072)
9c5908e050 is described below
commit 9c5908e050476ac10762a123ca41034343804084
Author: eladkal <[email protected]>
AuthorDate: Fri May 5 00:51:56 2023 +0300
`StepFunctionStartExecutionOperator`: get logs in case of failure (#31072)
In case of unsuccessful execution `output` is not set. Instead `error` is
set.
---
airflow/providers/amazon/aws/operators/step_function.py | 8 ++++++--
tests/providers/amazon/aws/operators/test_step_function.py | 7 +++++--
2 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/airflow/providers/amazon/aws/operators/step_function.py
b/airflow/providers/amazon/aws/operators/step_function.py
index c131dabc74..2aa8bdd8e2 100644
--- a/airflow/providers/amazon/aws/operators/step_function.py
+++ b/airflow/providers/amazon/aws/operators/step_function.py
@@ -113,8 +113,12 @@ class StepFunctionGetExecutionOutputOperator(BaseOperator):
hook = StepFunctionHook(aws_conn_id=self.aws_conn_id,
region_name=self.region_name)
execution_status = hook.describe_execution(self.execution_arn)
- execution_output = json.loads(execution_status["output"]) if "output"
in execution_status else None
+ response = None
+ if "output" in execution_status:
+ response = json.loads(execution_status["output"])
+ elif "error" in execution_status:
+ response = json.loads(execution_status["error"])
self.log.info("Got State Machine Execution output for %s",
self.execution_arn)
- return execution_output
+ return response
diff --git a/tests/providers/amazon/aws/operators/test_step_function.py
b/tests/providers/amazon/aws/operators/test_step_function.py
index 0c2320c492..566e134a86 100644
--- a/tests/providers/amazon/aws/operators/test_step_function.py
+++ b/tests/providers/amazon/aws/operators/test_step_function.py
@@ -20,6 +20,8 @@ from __future__ import annotations
from unittest import mock
from unittest.mock import MagicMock
+import pytest
+
from airflow.providers.amazon.aws.operators.step_function import (
StepFunctionGetExecutionOutputOperator,
StepFunctionStartExecutionOperator,
@@ -58,9 +60,10 @@ class TestStepFunctionGetExecutionOutputOperator:
assert REGION_NAME == operator.region_name
@mock.patch("airflow.providers.amazon.aws.operators.step_function.StepFunctionHook")
- def test_execute(self, mock_hook):
+ @pytest.mark.parametrize("response", ["output", "error"])
+ def test_execute(self, mock_hook, response):
# Given
- hook_response = {"output": "{}"}
+ hook_response = {response: "{}"}
hook_instance = mock_hook.return_value
hook_instance.describe_execution.return_value = hook_response