https://prefect.io logo
Title
g

Giacomo Chiarella

04/21/2023, 1:50 PM
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

flapili

04/21/2023, 1:51 PM
are you using async keyword ?
to declare the function
g

Giacomo Chiarella

04/21/2023, 1:53 PM
it is not in a function. I’ve declared the flow like
@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

flapili

04/21/2023, 1:53 PM
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

Giacomo Chiarella

04/21/2023, 2:03 PM
I’ve tried this:
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

flapili

04/21/2023, 2:04 PM
client.read_deployment is a coro
you must await it
g

Giacomo Chiarella

04/21/2023, 2:04 PM
oh yeah, forgot it
as far as you know, is there a way to delete all the flows that have no deployments?
d

Deceivious

04/21/2023, 2:08 PM
Not from UI. But using API yes
g

Giacomo Chiarella

04/21/2023, 2:08 PM
I cannot find anything in prefect python package, could you point out?
d

Deceivious

04/21/2023, 2:09 PM
The
client
should have access to deployments
g

Giacomo Chiarella

04/21/2023, 2:10 PM
I’m talking about flows
f

flapili

04/21/2023, 2:10 PM
you can by api but
d

Deceivious

04/21/2023, 2:10 PM
and flows.
g

Giacomo Chiarella

04/21/2023, 2:10 PM
if I get flows I do not get any info about attached deployments
f

flapili

04/21/2023, 2:10 PM
it will be O square complexity
d

Deceivious

04/21/2023, 2:11 PM
U can get deployments - deployment have attached flows. All flows - deployements.flows.id = not deployed flows
g

Giacomo Chiarella

04/21/2023, 2:11 PM
I thought there was something more easy
f

flapili

04/21/2023, 2:11 PM
basically it's a double nested loops
g

Giacomo Chiarella

04/21/2023, 2:12 PM
the cli has
prefect deployment delete
command but there is not a counterpart in flow command
f

flapili

04/21/2023, 2:12 PM
btw what's your usecase ?
d

Deceivious

04/21/2023, 2:13 PM
client.delete_deployment()
g

Giacomo Chiarella

04/21/2023, 2:13 PM
just cleaning
f

flapili

04/21/2023, 2:13 PM
then juste delete all flows
they should be repopulated when deploy will run
g

Giacomo Chiarella

04/21/2023, 2:13 PM
this means that I should delete all flows and deploy again
f

flapili

04/21/2023, 2:14 PM
no
g

Giacomo Chiarella

04/21/2023, 2:14 PM
and if there are running flows that would not be good solution
d

Deceivious

04/21/2023, 2:14 PM
If your are running a prefect server, run a single query to generate the infomation directly on the database 😄
f

flapili

04/21/2023, 2:14 PM
flows =/= flows run
g

Giacomo Chiarella

04/21/2023, 2:15 PM
can I use some orion api instead of direct db query?
d

Deceivious

04/21/2023, 2:17 PM
edit: Cant use a single api tofetch flow runs without deployments
g

Giacomo Chiarella

04/21/2023, 2:18 PM
ok, I will see
d

Deceivious

04/21/2023, 2:20 PM
client.read_flow_runs(FlowRunFilter=FlowRunFilter(deployment_id={"is_null_":True}))
@Giacomo Chiarella Try this.
g

Giacomo Chiarella

04/21/2023, 2:21 PM
great! I will definitely try it! Thanks!
d

Deceivious

04/21/2023, 2:21 PM
Actually use this code and test it before actually putting the values through the deletion process. Use at ur own risk xD
g

Giacomo Chiarella

04/21/2023, 2:22 PM
ahah yeah no worries. If I remember correctly, orion has an endpoint where you can send queries, right?
f

flapili

04/21/2023, 2:23 PM
you speak about /docs ?
a webui
d

Deceivious

04/21/2023, 2:24 PM
/api
g

Giacomo Chiarella

04/21/2023, 2:24 PM
it was like an elasticsearch but not elasticsearch. /api gives 404
d

Deceivious

04/21/2023, 2:30 PM
I vaguely rememeber ES like interface. /api by itself doesnt do anything. Check out valid endpoints on /docs