Hey all! Is there a straight-forward way to retrie...
# ask-community
s
Hey all! Is there a straight-forward way to retrieve flow_id(s)/flow_name(s)/deployment_id(s) after deploying the flow(s)? P.S. I am aware that the deployment_id is provided in the output logs of
prefect deploy
but it's not the easiest to parse through.
For more background: we are trying to use the Update Automation API call to add/remove flow(s) from the triggers.
n
hi @Sayantani Bhattacharjee - you can use the client if you want
Copy code
In [1]: from prefect import get_client

In [2]: async with get_client() as client:
   ...:     deployment = await client.read_deployment_by_name("foo/foo")
   ...:     print(deployment.id)
   ...:
9ff2c2fc-f98e-4734-bda2-6c5c5331a136
s
Hey @Nate, Thanks for that. However, the deployment name in your example requires the naming convention
<flow_name>/<deployment_name>
. My understanding of the flow_name is that it's either the value of the name argument passed in the
@flow
decorator or the function name which is declared as the flow (only if the flow decorator does not have a value for the name argument). Is there a way of extracting the name declared in the
@flow
decorator after the flow is deployed? The reason I ask is that, for our scenario, we have our flow declaration in a dummy file `src/flow1.py` is as shown below:
Copy code
@flow(name="Test flow")
def test_flow():
  ...
and our deployment section to the flow in prefect.yaml is as follows:
Copy code
{"name": "test_flow_deploy1"
 "entrypoint": "src/flow1.py:test_flow"
 ...}
In the above case, when we deploy our flow, the deployment name will be
Test flow/test_flow_deploy1
and according to your example, we will need to provide this entire deployment name to get the flow ID. That is a bit of a blocker for us as the flow_name section of the deployment_name is not referred anywhere else other than while declaring the flow decorator. Does flow decorator have some metadata that we could perhaps leverage for our use-case?
n
My understanding of the flow_name is that it's either the value of the name argument passed in the
@flow
decorator or the function name which is declared as the flow (only if the flow decorator does not have a value for the name argument).
correct! you can see what the api has stored if you do a quick
prefect deployment ls
- there's a few different ways to fetch that reliably, you can use
client.read_deployments
- are you having to dynamically discover the flow name supplied to the
@flow
decorator??
s
Ideally, we would like to dynamically get the new flow names or flow IDs that have just been deployed (immediately after
prefect deploy
runs successfully)