Skip to content
This repository was archived by the owner on Feb 20, 2025. It is now read-only.

Commit 6e06b57

Browse files
committed
fix: clean up step instantiation
1 parent e6843ec commit 6e06b57

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

hatchet_sdk/v2/workflows.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ def __init__(
116116
self,
117117
fn: Callable[[Any, Context], R] | Callable[[Any, Context], Awaitable[R]],
118118
type: StepType,
119-
workflow: Union["BaseWorkflow", None] = None,
120119
name: str = "",
121120
timeout: str = "60m",
122121
parents: list[str] = [],
@@ -130,7 +129,7 @@ def __init__(
130129
) -> None:
131130
self.fn = fn
132131
self.is_async_function = is_async_fn(fn)
133-
self.workflow = workflow
132+
self.workflow: Union["BaseWorkflow", None] = None
134133

135134
self.type = type
136135
self.timeout = timeout
@@ -146,7 +145,9 @@ def __init__(
146145

147146
def call(self, ctx: Context) -> R:
148147
if not self.is_registered:
149-
raise ValueError("Only steps that have been registered can be called.")
148+
raise ValueError(
149+
"Only steps that have been registered can be called. To register this step, instantiate its corresponding workflow."
150+
)
150151

151152
if self.is_async_function:
152153
raise TypeError(f"{self.name} is not a sync function. Use `acall` instead.")
@@ -159,7 +160,9 @@ def call(self, ctx: Context) -> R:
159160

160161
async def acall(self, ctx: Context) -> R:
161162
if not self.is_registered:
162-
raise ValueError("Only steps that have been registered can be called.")
163+
raise ValueError(
164+
"Only steps that have been registered can be called. To register this step, instantiate its corresponding workflow."
165+
)
163166

164167
if not self.is_async_function:
165168
raise TypeError(
@@ -207,6 +210,9 @@ class BaseWorkflow:
207210
def __init__(self) -> None:
208211
self.config.name = self.config.name or str(self.__class__.__name__)
209212

213+
for step in self.steps:
214+
step.workflow = self
215+
210216
def get_service_name(self, namespace: str) -> str:
211217
return f"{namespace}{self.config.name.lower()}"
212218

hatchet_sdk/worker/worker.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,6 @@ def register_workflow(self, workflow: Union["BaseWorkflow", Any]) -> None:
123123
sys.exit(1)
124124

125125
for step in workflow.steps:
126-
step.workflow = workflow
127-
128126
action_name = workflow.create_action_name(namespace, step)
129127
self.action_registry[action_name] = step
130128
return_type = get_type_hints(step.fn).get("return")

0 commit comments

Comments
 (0)