temporalio/sdk-python

[Feature Request] add "id_conflict_policy" arg for "execute_child_workflow"

johnny-smitherson opened this issue · 3 comments

Is your feature request related to a problem? Please describe.

The new id_conflict_policy arg is very useful to reduce the amount of try/except one has to use in workflows. But it doesn't work for start_child_workflow(...) / execute_child_workflow.

Describe the solution you'd like

await workflow.execute_child_workflow(
    ...,
    id_conflict_policy=WorkflowIDConflictPolicy.USE_EXISTING,  # master branch only
)

---> TypeError: execute_child_workflow() got an unexpected keyword argument 'id_conflict_policy'

Additional context

Is this a limitation of the API (and requires additions there too), or just the python library?

API PR was here temporalio/api#359

If filed in wrong place, please move issue

Thank you!

Is this a limitation of the API (and requires additions there too)

This is a limitation of the API

If filed in wrong place, please move issue

We can move to server repo, but there is a question of whether this is needed.

As a workflow author, you are the starter of the child workflows in your workflow and the listener of their completion states. Therefore you can perform whatever conflict resolution you'd like instead of the limited set offered by this value. We recommend using WorkflowAlreadyStartedError and consider it a healthy use of try/except. You can wrap it in a helper if needed, but I am not sure we want to do this helper (this is shown as an error in history, and we think it's important for code and history to be clear on these things).

Ah yes I see - for child tasks i can do

try:
        return await workflow.execute_child_workflow(
            ...
            id=the_id
        )
    except WorkflowAlreadyStartedError:
        handle = await workflow.get_external_workflow_handle(the_id)
        return await handle.result()

And that's more or less USE_EXISTING of the new param

or instead of handle.result(), I would terminate and restart to obtain the other behaviors of the param

Thanks!

get_external_workflow_handle does not return a handle with result. Getting a non-child result of a workflow from another workflow directly is not supported. Rather, if that already exists as a child, it means you started it some other time in your workflow. You can store that child handle on the class and access its result. If you need the result of a workflow that was not started as a child, you may have to break out into an activity and use the Temporal client.