Skip to content

Commit

Permalink
Early error on bad retry delay types (#16369)
Browse files Browse the repository at this point in the history
  • Loading branch information
cicdw authored Dec 12, 2024
1 parent 3abe9d0 commit 1d6ae61
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/prefect/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,10 @@ def __init__(

if callable(retry_delay_seconds):
self.retry_delay_seconds = retry_delay_seconds(retries)
elif not isinstance(retry_delay_seconds, (list, int, float, type(None))):
raise TypeError(
f"Invalid `retry_delay_seconds` provided; must be an int, float, list or callable. Received type {type(retry_delay_seconds)}"
)
else:
self.retry_delay_seconds = retry_delay_seconds

Expand Down
15 changes: 15 additions & 0 deletions tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4172,6 +4172,21 @@ def my_flow():


class TestTaskConstructorValidation:
async def test_task_cannot_configure_poorly_typed_retry_delay(self):
with pytest.raises(TypeError, match="Invalid"):

@task(retries=42, retry_delay_seconds=dict(x=4))
async def insanity():
raise RuntimeError("try again!")

with pytest.raises(TypeError, match="Invalid"):

@task(retries=42, retry_delay_seconds=2)
async def sanity():
raise RuntimeError("try again!")

more_insanity = sanity.with_options(retry_delay_seconds=dict(x=4)) # noqa: F841

async def test_task_cannot_configure_too_many_custom_retry_delays(self):
with pytest.raises(ValueError, match="Can not configure more"):

Expand Down

0 comments on commit 1d6ae61

Please sign in to comment.