Hi all, For tasks, is it possible to get options ...
# prefect-community
c
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
You could use
.submit
and a for loop instead of
.map
c
I see what you mean, but I really like using map(), so very curious if it's possible to combine with with_options()
z
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
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
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
Cool, thanks. Hope you add it as an argument to
map