Hi :wave: Any idea how to get the tags of the curr...
# ask-community
y
Hi 👋 Any idea how to get the tags of the current deployment inside the on_failure hook?
Copy code
def on_failure(flow, flow_run, state):
    # Would like somehow to get the tags from the deployment:
    tags = flow.deployment.tags
    print(tags)

@flow(name="test_flow", log_prints=True, on_failure=[on_failure])
def test_flow():
    print('hello')
    raise Exception('error')

test_flow()
b
Hi Yaron! One way that I think this may work is getting the tags from the flow run context. Flow runs inherit tags from their deployments. I got this example to work for me:
Copy code
from prefect import flow
from prefect.logging.loggers import flow_run_logger

def on_failure(flow, flow_run, state):
    flow_run_logger(flow_run, flow).info(f"Here are the tags for the flow {flow_run.tags}")

@flow(name="test_flow", log_prints=True, on_failure=[on_failure])
def test_flow():
    print('hello')
    raise Exception('error')

if __name__ == '__main__':
    test_flow.serve(name="test_flow", tags=["my-nice-test-tag"])
👍 1