Hi there. I am working on a flow that depends on a...
# prefect-community
p
Hi there. I am working on a flow that depends on a
start_date
and
end_date
. These can come from two
Parameters
or, if the parameters are not provided, the dates are computed after applying some logic to
prefect.context.scheduled_start_time
. I'd like to use the computed start and end dates for templating the task result's location. If these dates are passed as task inputs, they are accesible (I can do this
location="{start_date}_{end_date}.txt"
) but I'd also like to use these variables in some downstream tasks that don't list them as inputs. Is there another way for a downstream task to access these? Since they don't always come from a Parameter, they are not available in
prefect.context.paramters
. I tried adding them to the context at run time with
prefect.context["start_date"] = start_dt
but modifying the context like this doesn't feel right. Any suggestions?
n
Hi @Pedro Machado - I think the cleanest way to handle this would be to create an upstream task that will conditionally return the datetime object of your choosing; you can then reference the result of this task everywhere you need it without worrying about differing values or modifying the run context, and provide maximum visibility into where those important values are coming from.
👍 2
p
Thanks, Nicholas. I'll keep the dependencies explicit.
👍 1