running (registering) prefect flows with parameters on schedule

1.2k Views Asked by At

In prefect I would like to run flows with parameters on schedule. That sounds very natural to pass parameters, e.g. db credentials, right?

I have created a flow with parameters that runs well as prefect run -p flow.py --param db_config_path=somepath, now I would like to register it as prefect register --project project_name --path flow.py --name somename (with server started and agent running) to run on schedule.

However the server says: graphql_1 | {"severity": "ERROR", "name": "prefect-server.api.flows", "message": "Failed to set schedule to active while creating flow (flow_id={flow_id}).", "exc_info": "Traceback (most recent call last):\n File "/prefect-server/src/prefect_server/api/flows.py", line 285, in create_flow\n await api.flows.set_schedule_active(flow_id=flow_id)\n File "/prefect-server/src/prefect_server/api/flows.py", line 564, in set_schedule_active\n raise ValueError("Can not schedule a flow that has required parameters.")\nValueError: Can not schedule a flow that has required parameters."}

Moreover I found this:

https://github.com/PrefectHQ/prefect/issues/380

So it seems that flows with parameters are out of prefect paradigm? How do I pass db creds to the flows in this case?

1

There are 1 best solutions below

2
On

Couple of things:

  1. DB creds should ideally be secrets instead of parameters. On Prefect Cloud, you can store the secret with us and load it using the PrefectSecret task. On Server, you need to store local secrets. You can also see more on that here
  2. On the parameters, you can also do required=False so that you can register without a default.
  3. Parameters defaults on clocks/schedule don’t fulfill the requirement of having a default parameter because you can still trigger ad-hoc runs that would then not have any filled value.