https://prefect.io logo
#prefect-community
Title
# prefect-community
c

Christian Juhl

11/14/2022, 4:31 PM
Hi all, For tasks, is it possible to get options from with_options() mapped when using map()? For example, here I want to tag tasks running concurrently with letters from a dict, but when I do it this way, all tasks are tagged with all letters instead of letter to the corresponding number. Thanks!
Copy code
from prefect import task, flow

numbers = {
    'a': 1,
    'b': 2,
    'c': 3,
    'd': 4
}

@task
def square_number(number):

    return number ** 2

@flow
def my_flow():

    squared_numbers = square_number.with_options(tags=numbers.keys()).map(number=numbers.values())

    return squared_numbers

if __name__ == '__main__':

    output = my_flow()
z

Zanie

11/14/2022, 4:32 PM
You could use
.submit
and a for loop instead of
.map
c

Christian Juhl

11/14/2022, 4:34 PM
I see what you mean, but I really like using map(), so very curious if it's possible to combine with with_options()
z

Zanie

11/14/2022, 4:38 PM
Not at this time. I don’t think we really can, either. They’re separate operations and you could just call the task normally after
with_options
.
We’ll probably need to add another argument to
map
.
c

Christian Juhl

11/14/2022, 4:41 PM
Would be nice, and would make map() a lot better. What do you mean "you could just call the task normally after
with_options ?
z

Zanie

11/14/2022, 4:54 PM
Well.. you could do
new_task = square_number.with_options(tags="foo")
then later do
new_task()
or
new_task.submit()
.
with_numbers
does not know it is going to be chained with
map
so there’s not much we can do there for mapping-specific behavior.
c

Christian Juhl

11/14/2022, 4:56 PM
Cool, thanks. Hope you add it as an argument to
map
3 Views