Is there a specific kind of exception that can be ...
# ask-the-community
g
Is there a specific kind of exception that can be thrown in a task that would prevent retries from happening? I have a task I’d like to retry for various reasons, but if a specific known exception is thrown, I’d like to prevent the task from retrying
This looks to be default behavior for bare tasks, but when wrapped in dynamic, the task will retry:
Copy code
from flytekit import dynamic, task, workflow


@task(retries=2)
def test_task(x: int) -> int:
    raise Exception
    return x


@dynamic
def test_task_dynamic(x: int) -> int:
    return test_task(x=x)


@workflow
def test_workflow_dynamic(x: int) -> int:
    return test_task_dynamic(x=x)
^ In this case, the
test_task
retries multiple times
Actually thinking about this more, I can just do something like:
Copy code
from flytekit import dynamic, task, workflow
from flytekit.exceptions.user import FlyteRecoverableException


@task(retries=2)
def test_task(x: int) -> int:
    try:
        ...
    except KnownException:
       raise
    except Exception as e:
         raise FlyteRecoverableException("Other error") from e
    return x


@dynamic(retries=0)
def test_task_dynamic(x: int) -> int:
    return test_task(x=x)


@workflow
def test_workflow_dynamic(x: int) -> int:
    return test_task_dynamic(x=x)
153 Views