hello! is there a suggested way to access flow par...
# best-practices
r
hello! is there a suggested way to access flow parameter values or runtime specific information (e.g.
runtime.flow_run.id
) to use them in naming a flow_run (by passing them into `@prefect.flow`’s flow_run_name arg, or modifying them as part of some callable used to set flow_run_name) in prefect 2.14? i’d like to include key pieces of information particular to the flow run in the name if possible. thank you! cc: @Jon
same should work for flow_run_name
🙌 1
r
thanks Nate - i am seeing that yields a
MissingContextError
for a flow? This is the callable I’ve defined
Copy code
def generate_flow_run_name(
    flow_run_name_config: FlowRunNameConfig,
) -> str:
    """Get the flow run name.

    Args:
        flow_run_name_config (FlowRunNameConfig): flow run name configuration

    Returns:
        flow_run_name (str): flow run name
    """
    flow_run_name = flow_run_name_config.flow_name
    # some other code

    flow_run_name += f"-RUN-{get_run_context().flow_run.id}"

    return flow_run_name
n
hmm
do you have the full trace?
r
I do!
Copy code
Traceback (most recent call last):
  File "/Users/rowdy/Projects/data-capture/data-capture/projects/pipelines/dc/pipelines/source_meters_pipeline/schedule_flow.py", line 31, in <module>
    flow_run_name=generate_flow_run_name(
                  ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rowdy/Projects/data-capture/data-capture/projects/pipelines/dc/pipelines/utils/flow_run_utils.py", line 53, in generate_flow_run_name
    flow_run_name += f"-RUN-{get_run_context().flow_run.id}"
                             ^^^^^^^^^^^^^^^^^
  File "/Users/rowdy/Library/Caches/pypoetry/virtualenvs/pipelines-M_nR5Qnn-py3.11/lib/python3.11/site-packages/prefect/context.py", line 367, in get_run_context
    raise MissingContextError(
prefect.exceptions.MissingContextError: No run context available. You are not in a flow or task run context.
n
can you show the part that surrounds this?
Copy code
flow_run_name=generate_flow_run_name(
                  ^^^^^^^^^^^^^^^^^^^^^^^
are you calling the callable yourself?
because if you call it while defining the flow, it makes sense you wouldnt be inside a run context at that point
r
my bad - i totally get it now. I was trying to pass the return value instead of the callable itself facepalm thanks Nate!
👍 1
n
glad it makes sense now 🙂