sdk-python
sdk-python copied to clipboard
[Bug] workflow.start_child_workflow() behaving differently than workflow.execute_child_workflow() in tests
What are you really trying to do?
Hi there, I am writing tests for a workflow in which it spawns N child workflows using workflow.start_child_workflow()
, places them in a list, and resolves the result later, like the following example:
class Child:
async def run(self) -> bool:
return True
class Parent:
async def run(self, n: int):
children = []
for _ in range(n):
child = await workflow.start_child_workflow(Child, ...)
children.append(child)
...
for child in children:
result = await child.result()
# do something with result
and test code like the following:
async def test_parent():
# setup test env worker with both workflows
wf = await env.client.start_workflow("parent", ...)
await env.sleep(duration=timedelta(seconds=5))
await wf.result()
Describe the bug
Even when I have that exact child workflow, I get an InvalidStateError
saying Result is not set
. If I do not put the handler in a list and immediately call await child.result()
it blocks indefinitely. However if I use workflow.execute_child_workflow()
everything works fine. It's also worth noting these workflows work fine in an actual execution, this issue only exists using the testing.WorkflowEnvironment
.
Minimal Reproduction
Write a workflow that calls multiple child workflows using workflow.start_child_workflow()
, write a test with a single sleep before awaiting the parent's result.
Environment/Versions
- Ubuntu 22.04 AMD EPYC 7352
- Temporal 1.22.5 and Python SDK 1.3.0
- from source
Additional context
N/A