<@ULVA73B9P> What is the precedence of the setting...
# ask-marvin
u
@Marvin What is the precedence of the settings when both The
persist_result
parameter of the flow and task decorator and
PREFECT_RESULTS_PERSIST_BY_DEFAULT
and
PREFECT_TASKS_DEFAULT_PERSIST_RESULT
environment variables has been set?
m
thought for 110.0 seconds
Assuming Prefect 3.x, here’s the precedence when both decorator parameters and the two environment variables are set. For tasks (highest to lowest): 1) Explicit
@task(persist_result=...)
2)
PREFECT_TASKS_DEFAULT_PERSIST_RESULT
(if set, this overrides the parent flow’s setting) 3) Enclosing flow’s
persist_result
(from
@flow
) 4)
PREFECT_RESULTS_PERSIST_BY_DEFAULT
5) Otherwise False For flows (highest to lowest): 1) Explicit
@flow(persist_result=...)
2)
PREFECT_RESULTS_PERSIST_BY_DEFAULT
3) Otherwise False Notes: - Explicit decorator settings always win over env vars. - For tasks,
PREFECT_TASKS_DEFAULT_PERSIST_RESULT
takes precedence over both the flow’s setting and the global default. - Certain options implicitly enable persistence regardless of defaults: - Tasks: setting
cache_policy
,
cache_key_fn
,
result_storage_key
,
result_storage
, or
result_serializer
- Flows: setting
result_storage
or
result_serializer
Example: If
@flow(persist_result=True)
but
PREFECT_TASKS_DEFAULT_PERSIST_RESULT=False
, tasks will not persist unless you set
@task(persist_result=True)
explicitly.