```@flow @use_sentry def process_foo_deal(foo_paym...
# ask-community
t
Copy code
@flow
@use_sentry
def process_foo_deal(foo_payment_id: int) -> None:
    try:
        with get_nexus_session() as session:
            payment = get_payment(session=session, id=foo_payment_id)
            payment_state = get_payment_state(session=session, id=foo_payment_id)
            import_file_history = get_import_file_history(session=session, id=payment.importFileHistoryId)

            validate_payment_state(state=payment_state)

            deal_pdf_file_path = import_file_history.importFileUniqueName
            deal_pdf_file_name = import_file_history.importFileName.split("/")[-1]
@Marvin - here is a snippet of code. after deal_pdf_file_name is declared, i want to rename the flow run to that variable's value. How do i do this? I'm using Prefect 3
m
In Prefect 3.x, you can change the name of a flow run programmatically by interacting with the Prefect API. However, there doesn't seem to be direct documentation or a specific function to rename an ongoing flow run during its execution. You would typically set the name when you create the flow run. However, digging through the available information, one potential workaround is to use the
client
library to interact with Prefect's backend programmatically. Here’s a rough idea of how you might approach this: 1. Use the Prefect client to fetch the current flow run by ID. 2. Update the flow run's name using the
update_flow_run
method. Here’s a conceptual example (you can adapt this based on your exact use case):
Copy code
python
from prefect import flow, get_client
from prefect.client.orion import OrionClient

@flow
def process_foo_deal(foo_payment_id: int):
    # Your existing logic...
    
    deal_pdf_file_name = "Your file name logic"

    # Set the flow run name
    async def set_flow_run_name():
        async with OrionClient() as client:
            # Retrieve the current flow run ID
            flow_run = await client.read_flow_run(flow_run_id)
            # Update the flow run name
            flow_run.name = deal_pdf_file_name
            await client.update_flow_run(flow_run.id, flow_run)
    
    import asyncio
    asyncio.run(set_flow_run_name())

# Within your main logic
process_foo_deal(123)
For more detailed manipulation of flow runs, see Prefect's API capabilities (https://docs-3.prefect.io/v3/manage/interact-with-api). You might need to tailor the above logic to better fit your architecture and ensure you are capturing the current run's context correctly. I hope the universe is treating you better than some pieces of software. Keep on coding!