<@ULVA73B9P> my flow seems to run with values tha...
# ask-marvin
r
@Marvin my flow seems to run with values that are no longer in the code. I serve a deployment with multiple Cron schedules. (Tasks omitted for brevity.) from prefect import flow from prefect.server.schemas.schedules import Cron @flow def my_flow(list_schools, max_run_time, url_base): df = task_A(list_schools, max_run_time, url_base) task_B(df) if name == "__main__": URL_BASE = "www.sitesdasescolas.com.br" public_schools = ["2222-1111","2222-2222","2222-3333","2222-4444"] private_schools = ["3333-1111","3333-2222","3333-3333","3333-4444"] philanthropic_schools = ["5555-1111","5555-2222","5555-3333","5555-4444"] schedules = [ Cron( "0 9,12,15,18,21 * * *", slug="public", timezone="America/Sao_Paulo", parameters={ "list_schools": public_schools, "max_run_time": 180, "url_base": URL_BASE, }, ), Cron( "0 9,17 * * *", slug="private", timezone="America/Sao_Paulo", parameters={ # NOTE: this might be a bug — see below "deployment_ids": private_schools, "max_run_time": 480, "url_base": URL_BASE, }, ), Cron( "0 9,12,15,18,21,23 * * *", slug="philanthropic", timezone="America/Sao_Paulo", parameters={ # NOTE: this might be a bug — see below "deployment_ids": philanthropic_schools, "max_run_time": 180, "url_base": URL_BASE, }, ), ] my_flow.serve( name="Flow escolas", schedules=schedules, version="1.0.0", pause_on_shutdown=False, tags=["escolas"], ) During the flow’s execution, I noticed the school codes in the private_schools list were wrong. I changed the list values to: private_schools = ["9999-1111","9999-2222","9999-3333","9999-4444"] Then I served/redeployed the flow again. When the scheduled run triggers, it still uses the old private values (the 3333-... list), not the updated 9999-... list. What might explain this behavior and how can I fix it?
m
thought for 442.1 seconds
Short answer: you’re seeing “stale” parameters because Prefect pre-creates scheduled flow runs. Those runs keep the parameters they had at the time they were created. Re-serving the deployment updates the schedule going forward, but any already-created runs will still use the old values. Two additional notes from your snippet: - In your
private
and
philanthropic
schedules you passed
deployment_ids
instead of
list_schools
. Your flow signature is
my_flow(list_schools, max_run_time, url_base)
, so those runs would not receive
list_schools
unless you fix that key. - In Prefect 3.x, schedule parameters are stored on the schedule and copied onto each created flow run. They’re not dynamically read from your code at trigger time. What to do now 1) Fix the parameter key and re-serve
Copy code
schedules = [
       Cron(
           "0 9,17 * * *",
           slug="private",
           timezone="America/Sao_Paulo",
           parameters={
               "list_schools": private_schools,  # <-- fix
               "max_run_time": 480,
               "url_base": URL_BASE,
           },
       ),
       Cron(
           "0 9,12,15,18,21,23 * * *",
           slug="philanthropic",
           timezone="America/Sao_Paulo",
           parameters={
               "list_schools": philanthropic_schools,  # <-- fix
               "max_run_time": 180,
               "url_base": URL_BASE,
           },
       ),
   ]
   my_flow.serve(name="Flow escolas", schedules=schedules, version="1.0.1", tags=["escolas"], pause_on_shutdown=False)
2) Clear or cancel any pre-created runs that still hold the old parameters - In the UI: go to your deployment → Scheduled tab → cancel/delete the old future runs. - Via CLI: - List scheduled runs:
Copy code
prefect flow-run ls --flow-name "my_flow" --state SCHEDULED --limit 200
- Cancel or delete each affected run:
Copy code
prefect flow-run cancel <RUN_ID>
or
Copy code
prefect flow-run delete <RUN_ID>
- You can inspect a run to confirm its parameters:
Copy code
prefect flow-run inspect <RUN_ID>
3) Optionally, reset the schedules to avoid confusion - List schedules on the deployment and grab the schedule IDs:
Copy code
prefect deployment schedule ls "Flow escolas"
- Pause or delete the old schedule (e.g., the “private” one), then re-serve (or create a new schedule with a new slug like
private-v2
):
Copy code
prefect deployment schedule pause "Flow escolas" <SCHEDULE_ID>
or
Copy code
prefect deployment schedule delete "Flow escolas" <SCHEDULE_ID>
Tips to avoid this next time - After changing schedule parameters, either change the schedule slug (to force a fresh schedule) or cancel/delete any pre-created “Scheduled” runs so only new runs (with updated parameters) remain. - Keep
enforce_parameter_schema=True
(the default for
serve
) so typos like
deployment_ids
vs
list_schools
are caught early. Docs for reference: - Schedules (Prefect 3) - Python schedule API