is it kosher to invoke a task inside a task?
# ask-community
k
is it kosher to invoke a task inside a task?
j
According to hillel, but shammai disagrees.
😂 3
But seriously, you can do it, but you'll want to call
task.run
inside the task, not
task()
itself.
k
so something like:
Copy code
@task
do stuff():
    if more_stuff:
        stuff_task.run()
j
Something like:
Copy code
@task
def task1(a, b):
    return a + b

@task
def task2(a, b, c):
    return task1.run(a, b) + c
k
ahh
yea
from my POV it seems pythonicly legal but it might be best for readability at the Flow level if every task was declared at flow level rather than nested
but convenience of triggering conditional tasks would be super powerful if it is allowed to arbitrarily declare tasks
j
I'm not sure I follow. Are you asking if calling tasks from within tasks is recommended? Or making a recommendation for something we should change in prefect?
k
i was just speculating
it wasn't a real question haha
however, I do want to know if it is necessary to
return task.run()
or if I can do a
task.run()
followed by
signal.SOMETHING
j
You can do whatever you want honestly.
task.run
calls the undecorated task function directly (the function you wrote before the
task
decorator was applied). But I'd recommend keeping things simple.
k
gotcha
I think that entirely answers what I need
thanks!!