https://prefect.io logo
Title
j

Jovan Visnjic

08/28/2020, 9:13 AM
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:
@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

nicholas

08/28/2020, 1:23 PM
Hi @Jovan Visnjic - which version of Prefect are you running and are you restarting your flows from the Prefect UI or API?
j

Jovan Visnjic

08/28/2020, 1:34 PM
I'm running
0.13.2
and I'm restarting flows from the UI.
n

nicholas

08/28/2020, 2:50 PM
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

Jovan Visnjic

08/31/2020, 7:05 AM
Thank you nicholas! Will give it a try.