https://prefect.io logo
Title
s

Stéphan Taljaard

01/11/2023, 9:18 AM
Is there a way to rename a flow already registered with Orion/Cloud? I want to change its name and not lose run history
1
😒ad-keanu: 1
I had hoped to use this API endpoint, but that seems to be only for updating tags 🤔 Thoughts?
🙁 1
1
Github issue created - https://github.com/PrefectHQ/prefect/issues/8154 This seems to not be possible at the moment.
a

Aleksandr Liadov

01/19/2023, 5:07 PM
@Stéphan Taljaard did you succeed to add tags to your flow on runtime? I always have “flow not found”, however I take id with:
prefect.context.get_run_context().flow_run.dict()["id"]
s

Stéphan Taljaard

01/19/2023, 5:17 PM
Hi Aleksandr! I didn't actually want to add tags to my flow; I wanted to rename existing flows. I'll quickly check if I can add tags to a flow run, at runtime
@Aleksandr Liadov This did the trick for me:
@task
async def set_flow_run_tags(tags: list[str]):
    task_run_context = prefect.context.get_run_context()
    flow_run_id = task_run_context.task_run.flow_run_id

    async with prefect.client.orion.get_client() as client:
        response = await client.update_flow_run(flow_run_id=flow_run_id, tags=tags)

@flow
def main():
    set_flow_run_tags(["tags", "at", "runtime"])
You trust it should also work similarly if you want to do it inside the flow itself (i.e. not as a task)
👍 1
🙌 1
a

Aleksandr Liadov

01/20/2023, 8:43 AM
@Stéphan Taljaard thanks a lot! At least I can add a tag now. P.S I can rename flow now, your trick is working 🦄
:highfive: 1
🙌 1
s

Stéphan Taljaard

01/20/2023, 8:47 AM
Note that renames the flow run, not really the flow itself. But I'm happy this is working 🎉
🙌 1