Skip to content

Commit b5b78fb

Browse files
authored
Merge branch 'main' into failure-conversion-failure
2 parents 1dd7b62 + fe46e1a commit b5b78fb

File tree

5 files changed

+362
-25
lines changed

5 files changed

+362
-25
lines changed

temporalio/client.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2177,9 +2177,6 @@ async def execute_update(
21772177
This will target the workflow with :py:attr:`run_id` if present. To use a
21782178
different run ID, create a new handle with via :py:meth:`Client.get_workflow_handle`.
21792179
2180-
.. warning::
2181-
This API is experimental
2182-
21832180
Args:
21842181
update: Update function or name on the workflow.
21852182
arg: Single argument to the update.
@@ -2284,9 +2281,6 @@ async def start_update(
22842281
This will target the workflow with :py:attr:`run_id` if present. To use a
22852282
different run ID, create a new handle with via :py:meth:`Client.get_workflow_handle`.
22862283
2287-
.. warning::
2288-
This API is experimental
2289-
22902284
Args:
22912285
update: Update function or name on the workflow. arg: Single argument to the
22922286
update.
@@ -2366,9 +2360,6 @@ def get_update_handle(
23662360
Users may prefer the more typesafe :py:meth:`get_update_handle_for`
23672361
which accepts an update definition.
23682362
2369-
.. warning::
2370-
This API is experimental
2371-
23722363
Args:
23732364
id: Update ID to get a handle to.
23742365
workflow_run_id: Run ID to tie the handle to. If this is not set,
@@ -2398,9 +2389,6 @@ def get_update_handle_for(
23982389
23992390
This is the same as :py:meth:`get_update_handle` but typed.
24002391
2401-
.. warning::
2402-
This API is experimental
2403-
24042392
Args:
24052393
update: The update method to use for typing the handle.
24062394
id: Update ID to get a handle to.

temporalio/workflow.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -778,9 +778,6 @@ def current_update_info() -> Optional[UpdateInfo]:
778778
This is powered by :py:mod:`contextvars` so it is only valid within the
779779
update handler and coroutines/tasks it has started.
780780
781-
.. warning::
782-
This API is experimental
783-
784781
Returns:
785782
Info for the current update handler the code calling this is executing
786783
within if any.
@@ -1512,6 +1509,13 @@ def _apply_to_class(
15121509
f"Multiple update methods found for {defn_name} "
15131510
f"(at least on {name} and {updates[update_defn.name].fn.__name__})"
15141511
)
1512+
elif update_defn.validator and not _parameters_identical_up_to_naming(
1513+
update_defn.fn, update_defn.validator
1514+
):
1515+
issues.append(
1516+
f"Update validator method {update_defn.validator.__name__} parameters "
1517+
f"do not match update method {update_defn.fn.__name__} parameters"
1518+
)
15151519
else:
15161520
updates[update_defn.name] = update_defn
15171521

tests/helpers/__init__.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import uuid
55
from contextlib import closing
66
from datetime import timedelta
7-
from typing import Awaitable, Callable, Optional, Sequence, Type, TypeVar
7+
from typing import Any, Awaitable, Callable, Optional, Sequence, Type, TypeVar
88

99
from temporalio.api.common.v1 import WorkflowExecution
1010
from temporalio.api.enums.v1 import IndexedValueType
@@ -14,11 +14,12 @@
1414
)
1515
from temporalio.api.update.v1 import UpdateRef
1616
from temporalio.api.workflowservice.v1 import PollWorkflowExecutionUpdateRequest
17-
from temporalio.client import BuildIdOpAddNewDefault, Client
17+
from temporalio.client import BuildIdOpAddNewDefault, Client, WorkflowHandle
1818
from temporalio.common import SearchAttributeKey
1919
from temporalio.service import RPCError, RPCStatusCode
2020
from temporalio.worker import Worker, WorkflowRunner
2121
from temporalio.worker.workflow_sandbox import SandboxedWorkflowRunner
22+
from temporalio.workflow import UpdateMethodMultiParam
2223

2324

2425
def new_worker(
@@ -128,3 +129,24 @@ async def workflow_update_exists(
128129
if err.status != RPCStatusCode.NOT_FOUND:
129130
raise
130131
return False
132+
133+
134+
# TODO: type update return value
135+
async def admitted_update_task(
136+
client: Client,
137+
handle: WorkflowHandle,
138+
update_method: UpdateMethodMultiParam,
139+
id: str,
140+
**kwargs,
141+
) -> asyncio.Task:
142+
"""
143+
Return an asyncio.Task for an update after waiting for it to be admitted.
144+
"""
145+
update_task = asyncio.create_task(
146+
handle.execute_update(update_method, id=id, **kwargs)
147+
)
148+
await assert_eq_eventually(
149+
True,
150+
lambda: workflow_update_exists(client, handle.id, id),
151+
)
152+
return update_task

tests/test_workflow.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,3 +418,26 @@ def test_workflow_init_not__init__():
418418
with pytest.raises(ValueError) as err:
419419
workflow.init(BadWorkflowInit.not__init__)
420420
assert "@workflow.init may only be used on the __init__ method" in str(err.value)
421+
422+
423+
class BadUpdateValidator:
424+
@workflow.update
425+
def my_update(self, a: str):
426+
pass
427+
428+
@my_update.validator # type: ignore
429+
def my_validator(self, a: int):
430+
pass
431+
432+
@workflow.run
433+
async def run(self):
434+
pass
435+
436+
437+
def test_workflow_update_validator_not_update():
438+
with pytest.raises(ValueError) as err:
439+
workflow.defn(BadUpdateValidator)
440+
assert (
441+
"Update validator method my_validator parameters do not match update method my_update parameters"
442+
in str(err.value)
443+
)

0 commit comments

Comments
 (0)