<@ULVA73B9P> When my task creates a task with task...
# ask-marvin
j
@Marvin When my task creates a task with task.submit, it shows up in the UI at the same level as the task that submitted it. Is there a way to have it nest one level down for folding/unfolding and easier browsing?
m
thought for 254.9 seconds
Short answer: not with tasks. In Prefect 3.x, tasks submitted with
task.submit()
are shown as sibling task runs in the UI. The UI only provides hierarchical nesting for subflows, not for tasks. If you want a fold/unfold experience, refactor the “outer step” into a subflow and run your inner tasks inside it. The parent flow will show a nested flow node you can expand, and the tasks will appear within that subflow’s run. Example:
Copy code
from prefect import flow, task

@task
def inner_task(x):
    return x * 2

@flow(name="outer-stage")
def outer_stage(x):
    a = inner_task.submit(x)
    b = inner_task.submit(x + 1)
    return a.result() + b.result()

@flow
def parent_flow():
    r1 = outer_stage(1)   # appears as a nested subflow in the UI
    r2 = outer_stage(10)  # another nested subflow
    return r1 + r2
A few notes: -
.submit()
(and
.delay()
) won’t change UI hierarchy; they’re for concurrency and/or remote execution, not nesting. - Tags and naming conventions can help with filtering but won’t create hierarchy. Docs for deeper dives: - Subflows and nesting: Flows (subflows and nesting) - Task invocation patterns (
.submit
,
.delay
): Tasks - Concurrency patterns: Run work concurrently - Visualizing structure: Visualize workflow structure If you share a small snippet of your current flow/task layout, I’m happy to suggest a clean subflow refactor to get the nesting you want.