Skip to content

Conversation

@EddieWhi
Copy link
Contributor

What does this PR do?

Update the docs for updating python search attributes.

Notes to reviewers

Stumbled across this issue when trying this out for the first time and deprecated method didn't cleanly validate through pyright. Assume this is the official mechanism for updating search attributes in python now?

@EddieWhi EddieWhi requested a review from a team as a code owner January 21, 2025 13:18
@CLAassistant
Copy link

CLAassistant commented Jan 21, 2025

CLA assistant check
All committers have signed the CLA.

@fairlydurable fairlydurable added the community-contributor This PR was submitted external to Temporal label Jan 21, 2025
@fairlydurable fairlydurable changed the title Use value_set/unset to update search attributes EDU-3817: Use value_set/unset to update search attributes Jan 21, 2025
@fairlydurable fairlydurable added the waiting-on-tech-review PR is blocked and waiting for tech review from Subject Matter Experts label Jan 21, 2025
@EddieWhi
Copy link
Contributor Author

Thanks for picking this up and tidying @fairlydurable :)

@kevinawoo
Copy link
Member

kevinawoo commented Feb 12, 2025

@EddieWhi workflow.upsert_search_attributes doc says:

The dictionary form of attributes is DEPRECATED and if used, result in invalid key types on the typed_search_attributes property in the info. 🔗python-sdk

So that means doing something like this is deprecated:

workflow.upsert_search_attributes({"CustomKeywordField": ["new-value"]})

However these methods aren't deprecated:

I wonder if pyright is incorrectly reporting this? I couldn't reproduce the deprecation warning with pyright 0.8.0 installed in PyCharm.

@EddieWhi
Copy link
Contributor Author

@EddieWhi workflow.upsert_search_attributes doc says:

The dictionary form of attributes is DEPRECATED and if used, result in invalid key types on the typed_search_attributes property in the info. 🔗python-sdk

So that means doing something like this is deprecated:

workflow.upsert_search_attributes({"CustomKeywordField": ["new-value"]})

However these methods aren't deprecated:

* [TypedSearchAttributes](https://github.com/temporalio/sdk-python/blob/acde42cc15e153a6e4eeff0ef347a58622d49d6a/temporalio/common.py#L439-L440)

* [SearchAttributePair](https://github.com/temporalio/sdk-python/blob/acde42cc15e153a6e4eeff0ef347a58622d49d6a/temporalio/common.py#L401-L402)

I wonder if pyright is incorrectly reporting this? I couldn't reproduce the deprecation warning with pyright 0.8.0 installed in PyCharm.

For reference, I ran the test using pyright v1.1.393 and python 3.12.3

Sorry if my original message wasn't clear. Explicitly, if I copy paste the example from the existing docs i.e. :

        customer_id_key = SearchAttributeKey.for_keyword("CustomerId")
        workflow.upsert_search_attributes(TypedSearchAttributes([
            SearchAttributePair(customer_id_key, "customer_2")
        ]))

I get the following from pyright:

error: Argument of type "TypedSearchAttributes" cannot be assigned to parameter "attributes" of type "SearchAttributes | Sequence[SearchAttributeUpdate[Unknown]]" in function "upsert_search_attributes"
    Type "TypedSearchAttributes" is not assignable to type "SearchAttributes | Sequence[SearchAttributeUpdate[Unknown]]"
      "TypedSearchAttributes" is not assignable to "Mapping[str, SearchAttributeValues]"
      "TypedSearchAttributes" is not assignable to "Sequence[SearchAttributeUpdate[Unknown]]" (reportArgumentType)

Although (from memory as I haven't taken the time to test again) it does actually work when run.

For completeness, I tried the deprecated dictionary form you mentioned above (workflow.upsert_search_attributes({"CustomKeywordField": ["new-value"]})) and that validates just fine for me too.

Hope that helps in some way.

@fairlydurable
Copy link
Contributor

Hi all! Just checking in for a status check on this ticket...

@AlmogBaku
Copy link

arrrghhh took me 2h until I landed on this!

LGTM

@AlmogBaku
Copy link

Im still not sure how to set attributes with the new notation when start_child_workflow or start_workflows... the code in the documentation seems broken

@fairlydurable

@EddieWhi EddieWhi force-pushed the update-search-attribute-docs branch from f38fe86 to a838cca Compare November 24, 2025 11:05
@vercel
Copy link

vercel bot commented Nov 24, 2025

@fairlydurable is attempting to deploy a commit to the Temporal Team on Vercel.

A member of the Team first needs to authorize it.

@vercel
Copy link

vercel bot commented Nov 24, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
temporal-documentation Ready Ready Preview Comment Nov 24, 2025 8:39pm

@jsundai
Copy link
Contributor

jsundai commented Nov 24, 2025

Thank you, @EddieWhi - looks great! 🎉The code example given seems to use the correct typed pattern (value_set() / value_unset()), which is the preferred approach.

Perhaps the dict-style call still type-checks and runs because it’s not programmatically marked as deprecated, but the Temporal Python SDK mark it as such in favor of the typed approach. Might need to do a docs sweep for any other non-typed forms in a separate PR.

@jsundai jsundai self-requested a review November 24, 2025 20:39
@jsundai jsundai merged commit f6194f2 into temporalio:main Nov 24, 2025
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contributor This PR was submitted external to Temporal waiting-on-tech-review PR is blocked and waiting for tech review from Subject Matter Experts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants