Sean Conroy
06/15/2023, 6:00 PMTypeError: 'list' object does not support the context manager protocol
or TypeError: 'generator' object does not support the context manager protocol
Here's one of my attempts. Any suggestions on how to do this?
from prefect import flow, task, tags
from prefect.context import TagsContext
def add_tags(tag):
with tags(tag):
yield
@flow()
def my_flow():
# print(TagsContext.get().current_tags)
print('inside flow')
tag_list = ['mytag1', 'mytag2']
with [add_tags(x) for x in tag_list]:
my_flow()
Nate
06/15/2023, 7:17 PMSean Conroy
06/15/2023, 7:22 PMNate
06/15/2023, 7:28 PMfrom prefect import flow, task, tags
from prefect.context import TagsContext
@flow(log_prints=True)
def my_flow():
print(TagsContext.get().current_tags)
with tags("foo", "bar"):
my_flow()
syntax becomes insufficient for your use caseSean Conroy
06/15/2023, 7:38 PMNate
06/15/2023, 7:40 PMDeceivious
06/15/2023, 7:44 PMSean Conroy
06/15/2023, 8:12 PMSean Conroy
06/15/2023, 8:13 PMwith tags()
Nate
06/15/2023, 8:22 PMcustomer_to_tags = {"customer 1": ["foo", "bar"], ...}
@flow
def customer_facing_flow(customer: str):
with tags(*(customer_to_tags.get(customer) or [])):
my_flow()
Sean Conroy
06/15/2023, 8:23 PMSean Conroy
06/15/2023, 8:32 PMTypeError: 'list' object is not callable
Nate
06/15/2023, 8:33 PMSean Conroy
06/15/2023, 8:34 PMfrom prefect import flow, tags
tags = ["foo", "bar"]
@flow
def my_flow():
print('inside flow')
@flow
def customer_facing_flow(customer: str):
with tags(*(tags or [])):
my_flow()
customer_facing_flow('customer 1')
Sean Conroy
06/15/2023, 8:34 PMNate
06/15/2023, 8:35 PMtags
like
from prefect import flow, tags
customer_tags = ["foo", "bar"]
@flow
def my_flow():
print('inside flow')
@flow
def customer_facing_flow(customer: str):
with tags(*(customer_tags or [])):
my_flow()
customer_facing_flow('customer 1')
Nate
06/15/2023, 8:36 PMtags
with a list which is not callableSean Conroy
06/15/2023, 8:37 PMSean Conroy
06/15/2023, 8:38 PMSean Conroy
06/15/2023, 8:38 PMNate
06/15/2023, 8:38 PM