<@ULVA73B9P> - is there a way to disable flow results persistence on a per run basis? I have a flow ...
k
@Marvin - is there a way to disable flow results persistence on a per run basis? I have a flow that has
result_storage='s3-bucket/flow-results'
as a kwarg in the decorator. This is the slug to an s3 block. When I am running unit tests I call the flow directly with
my_flow()
, I don't want the flow to write to s3 in that case, is there a way to accomplish this?
m
thought for 307.1 seconds
n
typically in tests we'd use a
LocalFilesystem()
block we create in a fixture that references
tmp_dir
or something and use
with_options
to set the
result_storage
kwarg (assuming you already have the s3 block hard coded into your flow and don't wanna change it for the sake of the tests
m
Yes — you can disable result persistence per run. Two easy options in Prefect 3.x: 1) Override on the call with with_options - This is the most direct way to turn off persistence for a single run, even if the flow was decorated with
result_storage=...
.
Copy code
# in your test
result = my_flow.with_options(persist_result=False, result_storage=None)()
-
persist_result=False
prevents writing results. -
result_storage=None
is optional here; it explicitly clears any storage configured on the decorator for this run. 2) Disable globally within a test using temporary settings - Handy if you want to disable persistence for an entire test or test module:
Copy code
from prefect.settings import temporary_settings, PREFECT_RESULTS_PERSIST_BY_DEFAULT

def test_my_flow():
    with temporary_settings({PREFECT_RESULTS_PERSIST_BY_DEFAULT: False}):
        my_flow()  # no writes to S3
- Alternatively, set env var during tests:
PREFECT_RESULTS_PERSIST_BY_DEFAULT=false
. Notes: - If any specific flow or task is explicitly defined with
persist_result=True
, that explicit setting will override the default. In that case, use
with_options(persist_result=False)
to force-disable it per run. - Using
result_storage=None
ensures there’s no storage target even if persistence were enabled elsewhere. Docs: - Results (Prefect 3.x) - Settings reference
n
the first option would work, the second wouldnt because that's the fallback result storage ("`_BY_DEFAULT`")