Just a simple question. Can I override `yesterday`...
# ask-community
a
Just a simple question. Can I override
yesterday
in context? Like this:
Copy code
with prefect.context(yesterday="2021-01-01"):
    flow.run(run_on_schedule=False, executor=LocalExecutor())
d
Hi @Andor Tóth! I would recommend using a Parameter with a default that you can overwrite: https://docs.prefect.io/core/concepts/parameters.html
a
But Parameters can't have a dynamic value as a default (i.e. yesterday)
the default can't be a callable, and it must be JSON serializable
d
However, you can overwrite context values in Flow Runs from the UI
Sure! But you can have a task respond to a static input
a
but I can't override the context from the CLI?
as you've said Context is better, because it can be specied on the UI
how should I do that with context?
d
You can also overwrite parameters in the UI
a
but, from CLI one can't override certain values?
d
For example:
Copy code
import pendulum

date = Parameter(name="date", default="yesterday")

@task
def generate_date(date_parameter):
    if date_parameter == 'yesterday'
        return pendulum.now().subtract(days=1)

    return pendulum.parse(date_parameter)
a
okay, I get that
but I don't get the thing with context
or should I use keys which are not used by default?
d
From the Flow Run page -> advanced options you can specify / overwrite configuration options
I believe that means the values need to be JSON serializable, however
a
okay, but I prefer backfilling 365 days from CLI
Copy code
with prefect.context(...):
   flow.run()
should do the same, no?
d
with a parameter it would be:
Copy code
for day in range(365):
    flow.run(run_on_schedule=False, parameters={"date": pendulum.now().subtract(days=day).to_date_string()})
You could also use a date range instead of a specific date, depending on how you’d like to organize your Flow Runs
a
ah, I see
d
Copy code
flow.run(parameters={"start_date": "2020-01-01", "end_date": "2021-01-01"})
a
in the meantime, I could make it work with context
I just had to use a different key
👍 1
d
Prefect doesn’t make any specific assumptions about time in your Flows, so you’re free to configure them as you see fit 😄
a
but there's a paragraph in the documentation regarding backfills
which suggests to override
today
for backfills
thanks for your help
and patience! 🙂
d
That’s because users who come from Airflow generally search for something like “prefect backfill” and are looking for an analogous functionality from Airflow, since Airflow DAGs/Schedules have a hard dependency on time
Anytime!
a
I can't deny, I am stuck with the Airflow mindset
d
It’s all good! It takes time to learn new ways of thinking =]