Hello! I am trying to use `PrefectResult` with pre...
# prefect-community
j
Hello! I am trying to use
PrefectResult
with prefect core server running on my local machine. According to the docs, I understood that it should cache the result in prefect's database. I am running this simple example, extended from the one in the docs, I just added random raising of exceptions:
Copy code
@task(result=PrefectResult())
def add(x, y=1):
    if random.random() > 0.7:
        raise Exception('I failed on purpose')

    return x + y


with Flow("my handled flow!") as flow:
    first_result = add.map(list(range(10)), y=unmapped(2))
When I restart the flow, it doesn't just run the failed mapped tasks, It runs all of them again, also the successful ones. On the other hand it works fine if I use
LocalResult
. Am I missing something? Any help would be much appreciated.
n
Hi @Jovan Visnjic - which version of Prefect are you running and are you restarting your flows from the Prefect UI or API?
j
I'm running
0.13.2
and I'm restarting flows from the UI.
n
Got it @Jovan Visnjic - I can definitely reproduce this so let me dig in a little bit.
Ah ok @Jovan Visnjic - the issue is that you're hoping for a cached result, which
PrefectResult()
doesn't provide out of the box; it instead provides data persistence for tasks in the event of failure. To allow re-use of the data you'll need to use a cache pattern (like
cache_for
and
cache_validator
). You can read more about that here.
j
Thank you nicholas! Will give it a try.