I’m executing `get_run_logger().info(get_client()....
# ask-community
g
I’m executing
get_run_logger().info(get_client().read_deployment(FlowRunContext.get().flow_run.deployment_id).name)
in a flow and I get
getAttributeError: 'coroutine' object has no attribute 'name'
I think this is something related to async coroutines. How can I solve it?
f
are you using async keyword ?
to declare the function
g
it is not in a function. I’ve declared the flow like
Copy code
@flow(name=DAG_NAME, retries=3, retry_delay_seconds=30, description="")
def somename(p1: str):
    get_run_logger().info(get_client().read_deployment(FlowRunContext.get().flow_run.deployment_id).name)
f
not sure if read_deployment is sync_compatible
according to the src there is no usage of sync_compatible
if you can't use async (due to non-async compatible lib as example) you have to use something like anyio.run, else you juste have to use async syntax
g
I’ve tried this:
Copy code
async def get_deployment_name():
    async with get_client() as client:
        return client.read_deployment(FlowRunContext.get().flow_run.deployment_id).name

@flow(name=DAG_NAME, retries=3, retry_delay_seconds=30, description="")
def somename(lineages: str):
    get_run_logger().info(asyncio.run(get_deployment_name()))
but I get the same error
f
client.read_deployment is a coro
you must await it
g
oh yeah, forgot it
as far as you know, is there a way to delete all the flows that have no deployments?
d
Not from UI. But using API yes
g
I cannot find anything in prefect python package, could you point out?
d
The
client
should have access to deployments
g
I’m talking about flows
f
you can by api but
d
and flows.
g
if I get flows I do not get any info about attached deployments
f
it will be O square complexity
d
U can get deployments - deployment have attached flows. All flows - deployements.flows.id = not deployed flows
g
I thought there was something more easy
f
basically it's a double nested loops
g
the cli has
prefect deployment delete
command but there is not a counterpart in flow command
f
btw what's your usecase ?
d
client.delete_deployment()
g
just cleaning
f
then juste delete all flows
they should be repopulated when deploy will run
g
this means that I should delete all flows and deploy again
f
no
g
and if there are running flows that would not be good solution
d
If your are running a prefect server, run a single query to generate the infomation directly on the database 😄
f
flows =/= flows run
g
can I use some orion api instead of direct db query?
d
edit: Cant use a single api tofetch flow runs without deployments
g
ok, I will see
d
client.read_flow_runs(FlowRunFilter=FlowRunFilter(deployment_id={"is_null_":True}))
@Giacomo Chiarella Try this.
g
great! I will definitely try it! Thanks!
d
Actually use this code and test it before actually putting the values through the deletion process. Use at ur own risk xD
g
ahah yeah no worries. If I remember correctly, orion has an endpoint where you can send queries, right?
f
you speak about /docs ?
a webui
d
/api
g
it was like an elasticsearch but not elasticsearch. /api gives 404
d
I vaguely rememeber ES like interface. /api by itself doesnt do anything. Check out valid endpoints on /docs