Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Run-time check for update validator signature #723

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

Merged
merged 4 commits into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions temporalio/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1512,6 +1512,13 @@ def _apply_to_class(
f"Multiple update methods found for {defn_name} "
f"(at least on {name} and {updates[update_defn.name].fn.__name__})"
)
elif update_defn.validator and not _parameters_identical_up_to_naming(
update_defn.fn, update_defn.validator
):
issues.append(
f"Update validator method {update_defn.validator.__name__} parameters "
f"do not match update method {update_defn.fn.__name__} parameters"
)
else:
updates[update_defn.name] = update_defn

Expand Down
23 changes: 23 additions & 0 deletions tests/test_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,3 +418,26 @@ def test_workflow_init_not__init__():
with pytest.raises(ValueError) as err:
workflow.init(BadWorkflowInit.not__init__)
assert "@workflow.init may only be used on the __init__ method" in str(err.value)


class BadUpdateValidator:
@workflow.update
def my_update(self, a: str):
pass

@my_update.validator # type: ignore
def my_validator(self, a: int):
pass

@workflow.run
async def run(self):
pass


def test_workflow_update_validator_not_update():
with pytest.raises(ValueError) as err:
workflow.defn(BadUpdateValidator)
assert (
"Update validator method my_validator parameters do not match update method my_update parameters"
in str(err.value)
)
Loading