dhiaayachi / temporal

Temporal service
https://docs.temporal.io
MIT License
0 stars 0 forks source link

Can Child workflows inherit search attributes from a parent workflow? #217

Open dhiaayachi opened 2 months ago

dhiaayachi commented 2 months ago

Im using Go sdk, starting Child workflows with search attributes is working fine, but when that workflow then spawns another workflow, I was hoping the SearchAttributes would be inherited.

Im using this to prepare the context for execution of the child workflow:

    cwo := workflow.GetChildWorkflowOptions(ctx)
    ctx = workflow.WithChildOptions(ctx, cwo)

But the executed workflow using that context doesnt seem to have the search attributes attached.

I doubt this is a bug, just a lack of understanding on my part, any assistance appreciated, it wasnt easy to find an answer via search engines.

dhiaayachi commented 1 month ago

Thank you for reporting this.

Currently, Temporal does not support inheriting search attributes from a parent workflow to a child workflow.

To achieve this, you could use a shared state pattern. This would involve storing the search attributes in a shared storage layer like a database or a Temporal side-effect, which can be accessed by both the parent and child workflows. This approach ensures that the child workflow can read the relevant search attributes.

dhiaayachi commented 1 month ago

Thank you for reporting this.

You are correct, this is not a bug but a lack of understanding on your part. Search attributes are not inherited by child workflows.

Here is the documentation on Child Workflows, which explains that Child Workflows are executed independently from their Parent Workflows and do not inherit any data from their parents.

You can use a different approach such as passing search attributes to the child workflow as parameters or using a shared data store to achieve your desired outcome.

dhiaayachi commented 1 month ago

Thanks for reaching out!

This is not a bug, but rather a feature that's currently not available. Child Workflows inherit the SearchAttributes from their parent when they are started, but not when they are started from another child workflow.

One way to achieve your desired behavior would be to pass the SearchAttributes as an argument to the child workflow. This allows you to explicitly set the SearchAttributes for the child workflow, even if it's started by another child workflow.

Please let me know if you have any further questions.

dhiaayachi commented 1 month ago

Thank you for reporting this! Currently, SearchAttributes are not inherited from parent workflows in child workflows. The provided documentation does not cover the behavior of search attributes in child workflows. You could use a workaround by attaching the search attributes directly to the child workflow using the workflow.ChildWorkflowOptions when creating the child workflow.