Theom
11/18/2025, 8:42 AMPREFECT_RESULTS_PERSIST_BY_DEFAULT to true and PREFECT_TASKS_DEFAULT_PERSIST_RESULT to false, task results will not be persisted by default (unless overriding setting on individual tasks), but final flow result will be persisted?Marvin
11/18/2025, 8:42 AMMarvin
11/18/2025, 8:45 AMPREFECT_TASKS_DEFAULT_PERSIST_RESULT=false, task results are not persisted by default. This task-level default takes precedence for tasks.
- With PREFECT_RESULTS_PERSIST_BY_DEFAULT=true, flow results are persisted by default. There’s no separate flow-level default env var, so flows use this setting.
You can still override per object:
- Tasks: @task(persist_result=True/False)
- Flows (including subflows): @flow(persist_result=True/False)
Example:
from prefect import flow, task
@task(persist_result=True) # overrides the task default
def compute(x):
return x + 1
@flow(persist_result=False) # overrides the flow default if you don't want the final flow result persisted
def my_flow():
return compute(1)
Docs and references:
- Results and persistence overview: Results (Prefect 3 docs)
- Relevant source (for precedence and defaults):
- prefect/results.py
- prefect/context.py
- prefect/flow_engine.py
Note: Ensure you have appropriate result storage configured (e.g., via result_storage on a flow/deployment) if you want persisted results to be written to a durable location. Subflows are flows, so they’ll follow the flow rule above unless you override persist_result on the subflow decorator.