-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Typed search attributes #366
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also test the schedules client to get the missing coverage.
"""Get a single search attribute value by key or fail with | ||
``KeyError``. | ||
""" | ||
ret = next((v for k, v in self if k == key), None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it not have made more sense to make the search attribute key indexable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is key indexable from the user POV. But the underlying collection is best as a collection of type-safe pairs IMO instead of a dict which can't really be genericized on a per entry basis.
temporalio/converter.py
Outdated
if len(val) != 1: | ||
continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we skipping this?
Is this behavior consistent with Java (too lazy to check myself).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe so. I was told this should never happen with newer ones and we want to be strict here. I will set a reminder to confirm w/ Java behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same in Java. For the strict interface if we get a list for non-keyword-list and it isn't a single value, server contract is wrong and we ignore.
temporalio/converter.py
Outdated
parser = _get_iso_datetime_parser() | ||
# We will let this throw | ||
val = parser(val) | ||
# If the value isn't the right type, we need to ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, do we ignore in Java too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this allows new types to come on board for older SDKs
start_signal: Optional[str] = None, | ||
start_signal_args: Sequence[Any] = [], | ||
rpc_metadata: Mapping[str, str] = {}, | ||
rpc_timeout: Optional[timedelta] = None, | ||
stack_level: int = 2, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this left over?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it's intentional as a way to set warning stack depth to report the bad line at. Arguably I shouldn't expose to users, but if they are a wrapper library/utility, they may want their warnings to be on outer stack too.
Schedule Workflow Action Typed Search Attribute ConundrumThis has mostly gone smoothly with the exception of one place: schedule workflow action search attributes. There are two outstanding issues that have to be solved here: Mutually Exclusive FieldsToday, we have the following property for schedule action start workflow: @dataclass
class ScheduleActionStartWorkflow(ScheduleAction):
# ...
search_attributes: temporalio.common.SearchAttributes Where typed_search_attributes: temporalio.common.SearchAttributes And then tell users to use one or the other. The way a schedule update occurs is we first describe the schedule, then pass it to their update function, then they can use
Options:
Any other options? Type Metadata MissingUsually, all uses of search attributes on the server are validated on the way in and are guaranteed to have So untyped search attributes for workflow schedule actions are missing this So what do we do when we are given an object to update that has old-style search attributes? What do we do when we are given a proto with only new-style typed attributes but they update it with old-style untyped attributes? EDIT: ConclusionOption 8 was chosen - make backwards incompatible change to replace field. |
(moving back to draft until this is figured out) |
…mporal-sdk-python into typed-search-attributes
…attributes # Conflicts: # temporalio/common.py # temporalio/worker/_workflow_instance.py # tests/helpers/__init__.py # tests/worker/test_workflow.py
…attributes # Conflicts: # temporalio/client.py # temporalio/workflow.py
temporalio/client.py
Outdated
search_attributes: temporalio.common.SearchAttributes | ||
typed_search_attributes: Optional[temporalio.common.TypedSearchAttributes] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💥 This is the backwards incompatible change
We cannot have both of these here and use this same object for input and output because there are is no good way to determine user intent. Users using the old field in either direction will get an error. This was deemed an acceptable risk and we will make it clear in release notes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How are you handling the case where a user describes a schedule in python created by the CLI/Go SDK that does not have type data?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After some discussion, what I am going to do is put untyped_search_attributes
on this class, which is meant to be read-only on create, but technically mutable on update (but typed will override it).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Marking ready for review now that schedule start workflow action issue mentioned above has been resolved via a 💥 breaking change to replace the rarely used |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just realized I never submitted this review. Anyway, the comments are not blocking.
Union[ | ||
temporalio.common.TypedSearchAttributes, | ||
temporalio.common.SearchAttributes, | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just make an alias for this so it's not repeated so much
What was changed
Implementation of typed search attributes. Specifically:
warnings
)TypedSearchAttributes
,SearchAttributeKey
,SearchAttributePair
, andSearchAttributeUpdate
abstractions totemporalio.common
moduletyped_search_attributes
propertytyped_search_attributes
property to workflow infoupsert_search_attributes
to accept either typed form or old form and have it update both info entries when set from the other (with some caveats setting typed from untyped)ScheduleActionStartWorkflow.search_attributes
withScheduleActionStartWorkflow.typed_search_attributes
since that object is used in both directions and we can't determine user intent. User using the old field name in either direction will see an exception immediately on client side (i.e. no behavior changes or accidental misuse). We also added anuntyped_search_attributes
field to this class to let untyped ones stay present on update. Release notes will be very clear here.