Is there a way to add a task attribute during runt...
# ask-community
a
Is there a way to add a task attribute during runtime? I have a task object created outside of the flow, but I would like to update the task arguments inside of the flow before running it. I'm on Prefect 1.3.0
k
Hi @Arun Giridharan, I believe this is possible. Here's an example where the task_run_name is created inside of the flow and applied.
a
Hi @Kalise Richmond Thank you for responding! My case is a little different than that. Here's an example.
Copy code
class Task1(Task):
    def __init__(attr=None):
         self.attr=attr

    @default_from_attributes(attr)
    def run(attr, other_param):
        ...

test_task = Task1()

with Flow() as flow:
    attr = generate_attr()
    first_output = test_task(attr_1, "first")
    second_output = test_task(attr_1, "second")
    third_output = test_task(attr_1, "third")
Instead of repeating adding attr_1 to the task parameters, I'd like to set attr_1 in the task, so that it will pick it up.
👀 1
k
hmm I'm not sure if that is possible. So like you would have a task that generates the attribute and sets it in the Task1 class?
a
Yep!