Update parent workflow status without depending on child workflow

I have a use case, where in parent workflow A initiates child workflow B using workflow.execute_child_workflow .
Irrespective of the child workflow status, I want my parent workflow status be updated to completed once it triggered the child like fire and forget.

is it doable in temporal python sdk ?

You can set the parent close policy of a child to abandon which will let the child continue even once you’ve completed the parent.

Setting policy to ABANDON is not serving my use case. I want my child to start only after successful parent execution and then once child workflow is triggered, parent should not wait for its completion/status, Instead me marked as completed. May be for my case i might have to trigger an external workflow rather than having a child /parent relationship. Do we have any samples in python sdk for testing the relationships of child and parent ?

This is exactly how ABANDON works. Are you sure you’re not calling execute_child_workflow instead of start_child_workflow? await execute_child_workflow waits on the child result, await start_child_workflow just waits on it to start. You can return right after it started.

Sure, you can run an activity that starts a workflow. That’s very similar to a abandoned child workflow start.

Can you clarify “testing the relationships”? We may not have a sample for every option (e.g. every parent close policy).

1 Like

Getting error RuntimeError: await wasn’t used with future
cleanup_child_workflow = await workflow.start_child_workflow(

I cannot replicate. For example, changing https://github.com/temporalio/samples-python/blob/092ac9cadb32f4c78c83ac649e3fb23f7e8f8b28/hello/hello_child_workflow.py#L26-L30 to

        child_handle = await workflow.start_child_workflow(
            ComposeGreetingWorkflow.run,
            ComposeGreetingInput("Hello", name),
            id="hello-child-workflow-workflow-child-id",
        )
        return await child_handle

Works without issue. Can you provide a standalone-runnable replication of the issue you’re seeing and we can help debug? Can even alter that same sample to demonstrate your issue.

activity1 = await workflow.execute_activity(
activity=Activity.start_test,
args=[‘ABC’, “server”],
start_to_close_timeout=timedelta(hours=6))

cleanup_child_workflow = await workflow.start_child_workflow(
CleanUpWorkflow.wf_clean_up,
{“string1”,“string2”},
id=“CleanUp”,
parent_close_policy=workflow.ParentClosePolicy.ABANDON)

return activity1, await cleanup_child_workflow

When an activity in my child workflow is stuck/failed, and when i try to terminate the child, my parent is also getting marked failed.
How do i get my parent not wait/ have any relationship with my child after triggering it.

I’m not following, is this a snippet to replicate your “await wasn’t used with future” error or have you moved past that?

Why are you awaiting the completion of the child workflow if you want to return from the function before it completes?

Do not wait on the child completion in the parent if you don’t want the parent to wait for child completion.

If i await , my parent is waiting for child though i use ABANDON

If i do not await on the result , I am getting error

{
“message”: “await wasn’t used with future”,
“source”: “”,
“stackTrace”: " File "I:\PyVirtualEnvs\temporal_virtual_env\lib\site-packages\temporalio\worker\_workflow_instance.py", line 289, in activate\n self._run_once(check_conditions=index == 1 or index == 2)\n\n File "I:\PyVirtualEnvs\temporal_virtual_env\lib\site-packages\temporalio\worker\_workflow_instance.py", line 1187, in _run_once\n raise self._current_activation_error\n\n File "I:\PyVirtualEnvs\temporal_virtual_env\lib\site-packages\temporalio\worker\_workflow_instance.py", line 1205, in _run_top_level_workflow_function\n await coro\n\n File "I:\PyVirtualEnvs\temporal_virtual_env\lib\site-packages\temporalio\worker\_workflow_instance.py", line 622, in run_workflow\n result_payloads = self._payload_converter.to_payloads([result])\n\n File "I:\PyVirtualEnvs\temporal_virtual_env\lib\site-packages\temporalio\converter.py", line 213, in to_payloads\n payload = converter.to_payload(value)\n\n File "I:\PyVirtualEnvs\temporal_virtual_env\lib\site-packages\temporalio\converter.py", line 494, in to_payload\n data=json.dumps(\n\n File "C:\JPMC\DEV\TMP\ds\tools\python3.10\latest\lib\json\init.py", line 238, in dumps\n **kw).encode(obj)\n\n File "C:\JPMC\DEV\TMP\ds\tools\python3.10\latest\lib\json\encoder.py", line 199, in encode\n chunks = self.iterencode(o, _one_shot=True)\n\n File "C:\JPMC\DEV\TMP\ds\tools\python3.10\latest\lib\json\encoder.py", line 257, in iterencode\n return _iterencode(o, 0)\n\n File "I:\PyVirtualEnvs\temporal_virtual_env\lib\site-packages\temporalio\converter.py", line 434, in default\n return list(o)\n",
“encodedAttributes”: null,
“cause”: null,
“applicationFailureInfo”: {
“type”: “RuntimeError”,
“nonRetryable”: false,
“details”: null
}
}

File “I:\PyVirtualEnvs\temporal_virtual_env\lib\site-packages\temporalio\worker_workflow_instance.py”, line 289, in activate
self._run_once(check_conditions=index == 1 or index == 2)

File “I:\PyVirtualEnvs\temporal_virtual_env\lib\site-packages\temporalio\worker_workflow_instance.py”, line 1187, in _run_once
raise self._current_activation_error

File “I:\PyVirtualEnvs\temporal_virtual_env\lib\site-packages\temporalio\worker_workflow_instance.py”, line 1205, in _run_top_level_workflow_function
await coro

File “I:\PyVirtualEnvs\temporal_virtual_env\lib\site-packages\temporalio\worker_workflow_instance.py”, line 622, in run_workflow
result_payloads = self._payload_converter.to_payloads([result])

File “I:\PyVirtualEnvs\temporal_virtual_env\lib\site-packages\temporalio\converter.py”, line 213, in to_payloads
payload = converter.to_payload(value)

File “I:\PyVirtualEnvs\temporal_virtual_env\lib\site-packages\temporalio\converter.py”, line 494, in to_payload
data=json.dumps(

File “C:\JPMC\DEV\TMP\ds\tools\python3.10\latest\lib\json_init_.py”, line 238, in dumps
**kw).encode(obj)

File “C:\JPMC\DEV\TMP\ds\tools\python3.10\latest\lib\json\encoder.py”, line 199, in encode
chunks = self.iterencode(o, _one_shot=True)

File “C:\JPMC\DEV\TMP\ds\tools\python3.10\latest\lib\json\encoder.py”, line 257, in iterencode
return _iterencode(o, 0)

File “I:\PyVirtualEnvs\temporal_virtual_env\lib\site-packages\temporalio\converter.py”, line 434, in default
return list(o)

I am a bit confused, just change:

return activity1, await cleanup_child_workflow

to

return activity1

You don’t even need to store the result of await start_child_workflow since you aren’t using that handle. If this is not clear/working, can you reduce your code down to your exact problem in a full runnable sample so I can run it and debug?

All along i was under the impression that if i dont return the child_handle , parent will not have any details about the child . I was wrong !

Removing the return of child_handle did the trick !
Thank you chad for your help answering me patiently .