Is there an easy way to disable retries for flows ...
# ask-community
m
Is there an easy way to disable retries for flows and tasks that have been declared as
@task(retries=5)
etc. during my tests without resorting to mocking?
I came up with the following cool and horrible workaround. We can make our tasks passthrough by patching the prefect decorator itself:
patched_task_decorator.py
I'd still really love for Prefect to provide a more out-of-the-box solution to this, though.
j
Following - I've had the same issue and didn't find an out of the box solution, so if there is one I'd love to hear it.
m
How did you end up working around this, @Jessica Smith?
j
Oh I didn't, it wasn't a high enough priority at the moment and I haven't needed to come back to it yet. I think I was going to try setting a global retry value and then toggle that based on a debug parameter kind of thing - it would only work for local testing but that's what I was worried about last I looked at it
n
the exact way I'd do this would depend on the scenario, I don't often have cases where my tests concern my flow settings, but this is the first / simplest way I thought of
Copy code
from copy import copy
from prefect import flow

@flow(retries=1)
def foo():
   raise ValueError("ack")

foo_ = copy(foo) # you could modify `foo` here directly too if you wanted to skip this

foo_.retries = None 

foo_() # immediately fails without retry
👍 1
m
But that would just modify the flow itself. Since the retries in this case are set on the individual task level, and the tasks are called by the flow I don't think that would work. My monkeypatching works fine for simple flows, but falls short when more complex Prefect features are used, such as
.submit
and checking the state. I could always get away with a
MagicMock
but at that point it's becoming more and more a unit test and less of an integration / e2e test. I guess that might play into why there isn't an obvious OOB solution for this yet.
n
But that would just modify the flow itself
yeah or the copy you care about in your testing - can you explain your situation where your unit tests depend on the flow/task settings?