Skip to content
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
6 changes: 4 additions & 2 deletions dotflow/core/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ def _run_action(self, *args, task=None, **kwargs):

is_async = asyncio.iscoroutinefunction(self.func)

for attempt in range(1, self.retry + 1):
max_attempts = max(1, self.retry)

for attempt in range(1, max_attempts + 1):
try:
if self.timeout:
executor = ThreadPoolExecutor(max_workers=1)
Expand Down Expand Up @@ -178,7 +180,7 @@ def _run_action(self, *args, task=None, **kwargs):
):
raise ExecutionWithClassError() from None

if attempt == self.retry:
if attempt == max_attempts:
raise last_exception from None

if task is not None:
Expand Down
23 changes: 23 additions & 0 deletions tests/core/test_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,29 @@ def test_instantiating_action_class_with_fail_retry(self):
for record in self._caplog.records:
self.assertEqual(record.message, error_message)

def test_retry_zero_still_executes_task_once(self):
call_count = {"n": 0}

def counting_step():
call_count["n"] += 1

inside = Action(counting_step, retry=0)
inside(task=self.task)

self.assertEqual(
call_count["n"],
1,
"retry=0 should execute the task exactly once, not zero times",
)

def test_retry_zero_raises_on_failure(self):
def always_fail():
raise ValueError("fail")

inside = Action(always_fail, retry=0)
with self.assertRaises(ValueError):
inside(task=self.task)

def test_sets_retry_status_before_retrying(self):
calls = {"count": 0}
statuses = []
Expand Down
Loading