If the task is cancelled, why does the parent flow...
# ask-community
s
If the task is cancelled, why does the parent flow is failed? I'm cancelling my task by returning Cancelled state when a condition is met.
Copy code
return Cancelled(message="User requested task cancellation!")
n
hi @Shahid Khan is this prefect 2.x or 3.x?
s
Prefect 3
Sorry @Nate, my mistake, there was an error in the flow for which the flow was failed. But now if I've your attention, can you help me in understanding of dynamically setting up
tags
for
task
. I can update the flow tags by:
Copy code
async with get_client() as client:
   await client.update_flow_run(flow_run_id=run_id, tags=tags)
Is there any
update_task_run
kinda function where I can update task tags dynamically? Thanks for the prompt response.
n
i don't think you need to use the client directly
Copy code
#[7]
from prefect import flow, task

#[8]
@task
def foo():
    pass


#[9]
@flow
def f():
    foo.with_options(tags=["asdf"])()


#[10]
f()
15:22:23.784 | INFO    | Flow run 'golden-dalmatian' - Beginning flow run 'golden-dalmatian' for flow 'f'
15:22:23.786 | INFO    | Flow run 'golden-dalmatian' - View at <http://localhost:4200/runs/flow-run/b2944caf-12cf-4de7-ba3b-77466be290de>
15:22:23.849 | INFO    | Task run 'foo-a38' - Finished in state Completed()
15:22:23.868 | INFO    | Flow run 'golden-dalmatian' - Finished in state Completed()
s
Thanks @Nate for the response. I've tried this but this does not fulfill my needs. I'm trying to update tag inside the task function on the condition of it being successful or not. For example, if alerts are generated inside task, I'm planning to tag
alert_status:found
, so that I can filter task with this tag and get the idea of number of alerts being generated. Is there any way to update the tags for the task inside the function in Prefect 3?
n
I would say this is a pretty atypical pattern, I would personally reach for a named state before updating tags on a task from within, but if you really need to do the latter then i would do it in a state hook like an on failure state hook
s
Thanks a lot Nate, I'll give this a try. Cheers for Prefect community.
n
catjam