I’m trying to construct a schedule with `parameter...
# ask-community
n
I’m trying to construct a schedule with
parameter_defaults
, where the defaults are derived from the date that the schedule is triggered on. In other words, I’m looking for something like this:
Copy code
schedule = Schedule(
    clocks=[
        IntervalClock(
            interval=timedelta(days=1),
            parameter_defaults={"version": date.today().isoformat()},
        ),
    ],
...
Except I don’t want
date.today().isoformat()
to be calculated just once when the flow is registered and then fixed for all time. I want it to be calculated at the time the clock fires. How do I do this? Pass in a lambda as the value in the
parameter_defaults
dictionary? Construct a dict-like object that calculates the value on key lookup? I feel like I’m thinking about this incorrectly.
k
Hey @Nicholas Chammas, I don’t think you can put a lambda or Callable as a parameter. The approach is likely using a string like “today” and then using a task to calculate it. Maybe you can pass an integer that is n days away from the current date, pass that to a task to return the date, and then use that in the flow.
👌 1
n
I’ll try using an intermediate task to compute the default at runtime. Do you think it makes sense for the API to support callables as parameter defaults in the future? I guess it would be complicated for Prefect since it would involve pickling/unpickling Python code. Perhaps not worth it at this time. Maybe an example in the docs is sufficient to show people how to meet this dynamic default parameter use case. I’ll share my code here when I have something working, if that helps.
k
I’m not super knowledgeable but I think it’s more about being JSON compliant for the API