bug(python-sdk): `spawn_workflow` feature bug due to misnamed `ClientImpl` `rest_client` property.
mathieudupoux opened this issue · 2 comments
mathieudupoux commented
Bug description
Use Child Workflow with spawn_workflow
feature lead to error
"This step failed with error 'ClientImpl' object has no attribute 'rest_client'"
Context
pip show hatchet-sdk
Name: hatchet-sdk
Version: 0.21.0
Summary:
Home-page:
Author: Alexander Belanger
Author-email: alexander@hatchet.run
License:
Location: /home/mathieu/Projet/Data Pipelines/Hatchet/sdk/venv/lib/python3.10/site-packages
Requires: aiostream, grpcio, grpcio-tools, loguru, protobuf, pydantic, python-dateutil, python-dotenv, pyyaml, urllib3
Required-by:
How to reproduce ?
I wrote a minimal PoC reproducing the issue:
from dotenv import load_dotenv
import asyncio
from hatchet_sdk import Hatchet, Context
load_dotenv()
hatchet = Hatchet(debug=True)
@hatchet.workflow(name="subflow", on_events=["user:create"])
class Subflow:
@hatchet.step()
def first_subflow_step(self, context: Context):
word: str = context.workflow_input()["word"]
return {
"word": word.capitalize()
}
@hatchet.workflow(name="mainflow", on_events=["user:create"])
class Mainflow:
@hatchet.step()
async def split_workflow(self, context: Context):
data = [
"this",
"is",
"awesome",
"!"
]
futures = []
for word in data:
future = context.spawn_workflow("subflow", input={"word": word})
futures.append(future.result())
results = await asyncio.gather(*futures)
return {
"sentence" : ' '.join([word["first_subflow_step"]["word"] for word in results])
}
worker = hatchet.worker('ChildTest', max_runs=100)
worker.register_workflow(Mainflow())
worker.register_workflow(Subflow())
worker.start()
Expected result :
{
"sentence": "This Is Awesome !"
}
Raised error :
[
"This step failed with error 'ClientImpl' object has no attribute 'rest_client'"
]
Solution
I found that rest_client
property of ClientImpl
class has been recently renamed to rest
. This change seems not to be propagated to context.py :
class ChildWorkflowRef:
...
def getResult(self) -> StepRunEvent:
try:
- res = self.client.rest_client.workflow_run_get(self.workflow_run_id)
+ res = self.client.rest.workflow_run_get(self.workflow_run_id)
Using the right property name solve the error and the workflow works.
abelanger5 commented
Thanks for the detailed bug report @mathieudupoux! Fixing this right away.
grutt commented
@mathieudupoux this should be fixed in Python SDK 0.21.1