<@ULVA73B9P> is there an easy way to rename the fl...
# ask-community
t
@Marvin is there an easy way to rename the flow run name, for example, somewhere in the flow I do:
file_name = generate_daily_file_name(_value_date_=_report_date_)
after
file_name
is generated, i'd like to set the current
flow_run_name
to this my prefect version is 3.0.11
hader popcorn 1
m
In Prefect 3.0.11, you can dynamically set the flow run name using a function when you define your flow. Here's a concise example from the Prefect documentation: You can create a function to generate the name and pass it using the
flow_run_name
parameter of the
flow
decorator.
Copy code
python
from prefect import flow
from prefect.runtime import flow_run

def generate_flow_run_name():
    # Access flow or parameter information
    flow_name = flow_run.flow_name
    parameters = flow_run.parameters
    name = parameters.get("name", "default")  # Use default value if 'name' is not a parameter
    return f"{flow_name}-with-{name}"

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

# Example usage
if __name__ == "__main__":
    my_flow(name="daily-report")
In this example, the
generate_flow_run_name
function utilizes the runtime module to access flow information or parameters, allowing it to create a customized name for each run. Make sure you adjust the function logic to suit your specific naming requirements. No current GitHub issues indicate problems with renaming flow run names dynamically, so you shouldn’t face any specific bugs related to this feature in Prefect 3.x.