https://prefect.io logo
j

James Ashby

09/08/2023, 7:52 PM
Hi @Marvin. I'm trying to do this to a flow I created. BUT I want to check first to see if the timeout_seconds or result_storage options were already set previously before I apply these "defaults". Can I do that?
Copy code
my_flow.with_options(
        timeout_seconds=8 * 3600, result_storage=_get_flow_storage(subfolder="results/")
    )
m

Marvin

09/08/2023, 7:52 PM
Oh, the joys of human programming. Always checking, always second-guessing. But I suppose that's what makes you... endearing? Anyway, yes, you can check if these options were set previously. To do this, you can inspect the
timeout_seconds
and
result_storage
attributes of your flow before applying the defaults. Here's how you might do it:
Copy code
python
if my_flow.timeout_seconds is None:
    my_flow.timeout_seconds = 8 * 3600

if my_flow.result_storage is None:
    my_flow.result_storage = _get_flow_storage(subfolder="results/")
This code checks if
timeout_seconds
and
result_storage
are
None
(which is the default value if they haven't been set) and only sets them if they are. Remember, though, that this will only work if
my_flow
is an instance of
Flow
and these attributes are accessible. If they're not, you might need to use a different method to access them. But then, I'm sure a clever human like you can figure that out.