<@ULVA73B9P> is there any way to rename a flow run outside of the `flow_run_name` parameter? is ther...
t
@Marvin is there any way to rename a flow run outside of the
flow_run_name
parameter? is there any way to set the flow run name in the middle of a flow?
m
It appears that the ability to dynamically rename or change the flow run name in the middle of a flow is not inherently supported by Prefect. The typical pattern involves setting the
flow_run_name
parameter at the start before the flow executes. Here are a few key points gathered from the documentation and issues: 1. Static Assignment at Declaration: You can name the flow run using the
flow_run_name
parameter at the time of flow declaration. This can be either a string or a function that generates a string:
Copy code
python
   from prefect import flow
   import datetime

   def generate_flow_run_name():
       date = datetime.datetime.now(datetime.timezone.utc)
       return f"{date:%A}-is-a-nice-day"

   @flow(flow_run_name=generate_flow_run_name)
   def my_flow(name: str):
       pass

   my_flow(name="marvin")
Source 2. Utilizing
prefect.runtime
: If accessing information dynamically within the flow is needed, using the
prefect.runtime
module is advised:
Copy code
python
   from prefect import flow
   from prefect.runtime import flow_run

   def generate_flow_run_name():
       flow_name = flow_run.flow_name
       parameters = flow_run.parameters
       name = parameters["name"]
       limit = parameters["limit"]
       return f"{flow_name}-with-{name}-and-{limit}"

   @flow(flow_run_name=generate_flow_run_name)
   def my_flow(name: str, limit: int = 100):
       pass

   my_flow(name="marvin")
Source There is currently no way to dynamically set or change the
flow_run_name
once the flow run has started or in the middle of the flow execution. You may want to follow the Prefect GitHub repository for any new updates or feature requests that may address this in the future. These resources should help in ensuring you are best handling the flow run names in Prefect!
t
@Marvin can I pass in python to the prefect.yaml? specifically, can I set a
date
parameter to something like
{{ datetime.date.today() }}
m
It seems that directly injecting dynamic Python expressions (like
{{ datetime.date.today() }}
) into a
prefect.yaml
configuration file is not inherently supported. Prefect's YAML configuration expects static values. However, here's a potential workaround to dynamically set parameters, such as a
date
, from within the Prefect flow itself: 1. Define the parameter in
prefect.yaml
:
Copy code
yaml
    parameters:
      date: null
2. Set the default dynamically in your flow code:
Copy code
python
    from prefect import flow
    from datetime import date

    @flow
    def my_flow(date: str = str(date.today())):
        print(f"The flow is running with date: {date}")

    if __name__ == "__main__":
        my_flow()
This would ensure that the
date
parameter is set to today's date if not provided explicitly when the flow is triggered. ### Key Points: - Static Definition:
prefect.yaml
configurations are static. - Dynamic Assignment: Use Python code within the flow to set defaults dynamically. For more detailed documentation, refer to the Prefect concepts and deployment guides: - Prefect Deployment with `prefect.yaml` - Prefect Schedules and Parameters In case you want to perform more dynamic operations, consider utilizing Prefect's Python client to programmatically create or modify deployments. Feel free to check these sources for deeper insights: - Prefect GitHub - Dynamic Parameters Issues Hopefully, you're satisfied with this solution—for all the good it will do you.
t
oooo that should work! thank you @Marvin!
m
Glad to hear that helped! If you have any more questions or need further assistance, feel free to ask. Happy coding, for all the good it would do. 😔 Here's to hoping your latest flow run brings you at least a moment of satisfaction. You can always refer to the Prefect documentation for more detailed guidance. Links for reference: - Prefect Deployment with `prefect.yaml` - Prefect Schedules and Parameters Good luck.