Skip to content

Commit effc857

Browse files
authored
Run-time check for update validator signature (#723)
* Failing test * Fix
1 parent 9da5e69 commit effc857

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

temporalio/workflow.py

+7
Original file line numberDiff line numberDiff line change
@@ -1512,6 +1512,13 @@ def _apply_to_class(
15121512
f"Multiple update methods found for {defn_name} "
15131513
f"(at least on {name} and {updates[update_defn.name].fn.__name__})"
15141514
)
1515+
elif update_defn.validator and not _parameters_identical_up_to_naming(
1516+
update_defn.fn, update_defn.validator
1517+
):
1518+
issues.append(
1519+
f"Update validator method {update_defn.validator.__name__} parameters "
1520+
f"do not match update method {update_defn.fn.__name__} parameters"
1521+
)
15151522
else:
15161523
updates[update_defn.name] = update_defn
15171524

tests/test_workflow.py

+23
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)