From 51ab7bb92f094aa2f9be27f38553d96d668a5ea9 Mon Sep 17 00:00:00 2001 From: mrkaye97 Date: Fri, 17 Jan 2025 10:43:41 -0500 Subject: [PATCH 1/5] feat: expose step run errors on context --- hatchet_sdk/context/context.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hatchet_sdk/context/context.py b/hatchet_sdk/context/context.py index 02838c50..734830fc 100644 --- a/hatchet_sdk/context/context.py +++ b/hatchet_sdk/context/context.py @@ -376,6 +376,9 @@ def child_key(self) -> str | None: def parent_workflow_run_id(self) -> str | None: return self.action.parent_workflow_run_id + def step_run_errors(self) -> dict[str, str]: + return cast(dict[str, str], self.input.get("step_run_errors", {})) + def fetch_run_failures(self) -> list[dict[str, StrictStr]]: data = self.rest_client.workflow_run_get(self.action.workflow_run_id) other_job_runs = [ From 64b7ebefaeae11ee62e1bfa91ba2fbf69b4bcef7 Mon Sep 17 00:00:00 2001 From: mrkaye97 Date: Fri, 17 Jan 2025 10:45:05 -0500 Subject: [PATCH 2/5] add to on failure example --- examples/on_failure/worker.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/examples/on_failure/worker.py b/examples/on_failure/worker.py index bf3967af..ddf12373 100644 --- a/examples/on_failure/worker.py +++ b/examples/on_failure/worker.py @@ -25,6 +25,10 @@ def step1(self, context: Context) -> None: def on_failure(self, context: Context) -> dict[str, str]: # 👀 we can do things like perform cleanup logic # or notify a user here + + # 👀 Fetch the errors from upstream step runs from the context + print(context.step_run_errors()) + return {"status": "success"} From 523d49ef70654091952cd8cbd8f385a41dd612f6 Mon Sep 17 00:00:00 2001 From: mrkaye97 Date: Fri, 17 Jan 2025 10:49:53 -0500 Subject: [PATCH 3/5] fix: wrong key --- hatchet_sdk/context/context.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hatchet_sdk/context/context.py b/hatchet_sdk/context/context.py index 734830fc..5cab750e 100644 --- a/hatchet_sdk/context/context.py +++ b/hatchet_sdk/context/context.py @@ -377,7 +377,7 @@ def parent_workflow_run_id(self) -> str | None: return self.action.parent_workflow_run_id def step_run_errors(self) -> dict[str, str]: - return cast(dict[str, str], self.input.get("step_run_errors", {})) + return cast(dict[str, str], self.data.get("step_run_errors", {})) def fetch_run_failures(self) -> list[dict[str, StrictStr]]: data = self.rest_client.workflow_run_get(self.action.workflow_run_id) From 5454662ba5777028d0c0cd479b7c95a069a0609c Mon Sep 17 00:00:00 2001 From: mrkaye97 Date: Fri, 17 Jan 2025 14:59:27 -0500 Subject: [PATCH 4/5] feat: log an error if no errors are found --- hatchet_sdk/context/context.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/hatchet_sdk/context/context.py b/hatchet_sdk/context/context.py index 5cab750e..f20acd66 100644 --- a/hatchet_sdk/context/context.py +++ b/hatchet_sdk/context/context.py @@ -377,7 +377,14 @@ def parent_workflow_run_id(self) -> str | None: return self.action.parent_workflow_run_id def step_run_errors(self) -> dict[str, str]: - return cast(dict[str, str], self.data.get("step_run_errors", {})) + errors = cast(dict[str, str], self.data.get("step_run_errors", {})) + + if not errors: + logger.error( + "No step run errors found. `context.step_run_errors` is intended to be run in an on-failure step, and will only work on engine versions more recent than v0.53.10" + ) + + return errors def fetch_run_failures(self) -> list[dict[str, StrictStr]]: data = self.rest_client.workflow_run_get(self.action.workflow_run_id) From b97cb1e86edf96cb9729a0e48e6dd11db1fd64b3 Mon Sep 17 00:00:00 2001 From: mrkaye97 Date: Fri, 17 Jan 2025 18:28:02 -0500 Subject: [PATCH 5/5] chore: version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 884f6af3..b332d11e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "hatchet-sdk" -version = "0.43.3" +version = "0.44.0" description = "" authors = ["Alexander Belanger "] readme = "README.md"