Skip to content

Commit 772050e

Browse files
Add backward compatibility for dynamic handler signatures (#1258)
* Add backward compatibility for dynamic handler signatures * Linting --------- Co-authored-by: Tim Conley <[email protected]>
1 parent 44770ff commit 772050e

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

temporalio/workflow.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import inspect
88
import logging
99
import threading
10+
import typing
1011
import uuid
1112
import warnings
1213
from abc import ABC, abstractmethod
@@ -1919,7 +1920,10 @@ def _assert_dynamic_handler_args(
19191920
not arg_types
19201921
or len(arg_types) != 2
19211922
or arg_types[0] != str
1922-
or arg_types[1] != Sequence[temporalio.common.RawValue]
1923+
or (
1924+
arg_types[1] != Sequence[temporalio.common.RawValue]
1925+
and arg_types[1] != typing.Sequence[temporalio.common.RawValue]
1926+
)
19231927
):
19241928
raise RuntimeError(
19251929
"Dynamic handler must have 3 arguments: self, str, and Sequence[temporalio.common.RawValue]"

tests/test_workflow.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import inspect
22
import itertools
3+
import typing
34
from collections.abc import Callable, Sequence
45
from typing import Any, Set, Type, get_type_hints
56

@@ -70,6 +71,27 @@ def update3(self, name: str, args: Sequence[RawValue]):
7071
pass
7172

7273

74+
@workflow.defn()
75+
class GoodDefnDeprecatedTypes(GoodDefnBase):
76+
# Just having the definition here is enough to confirm the signatures
77+
# do not trigger a RuntimeError
78+
@workflow.run
79+
async def run(self, name: str) -> str:
80+
raise NotImplementedError
81+
82+
@workflow.signal(dynamic=True)
83+
def signal(self, name: str, args: typing.Sequence[RawValue]):
84+
pass
85+
86+
@workflow.query(dynamic=True)
87+
def query(self, name: str, args: typing.Sequence[RawValue]):
88+
pass
89+
90+
@workflow.update(dynamic=True)
91+
def update(self, name: str, args: typing.Sequence[RawValue]):
92+
pass
93+
94+
7395
def test_workflow_defn_good():
7496
# Although the API is internal, we want to check the literal definition just
7597
# in case

uv.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)