https://dagster.io/ logo
Title
m

Mark Fickett

03/04/2022, 1:38 AM
When multiple values are returned form an op, how does Dagster figure out which is which? Are they just sorted by output name or dict key order? In the conditional branching docs, there's this example. But if I set it to always yield
branch_1
but then assign
branch_2, branch_1 = branching_op()
in my
@job
, then I get backwards execution.
# <https://docs.dagster.io/concepts/ops-jobs-graphs/jobs-graphs#conditional-branching>
import random

from dagster import Out, Output, job, op


@op(out={"branch_1": Out(is_required=False), "branch_2": Out(is_required=False)})
def branching_op():
    num = 0
    if num == 0:
        yield Output(1, "branch_1")
    else:
        yield Output(2, "branch_2")


@op
def branch_1_op(_input):
    pass


@op
def branch_2_op(_input):
    pass


@job
def branching():
    branch_2, branch_1 = branching_op()  # Does this always return branch_1, branch_2? Why?
    branch_1_op(branch_1)
    branch_2_op(branch_2)
a

alex

03/04/2022, 7:32 PM
Does this always return branch_1, branch_2? Why?
The object representing the multiple outputs is a
namedtuple
. You can destructure as you are based on the order of elements in the tuple. The order is determined by the order of the dictionary passed to
out
. The name of the variables you assign to has no effect. You can capture the tuple directly and then key using the names of the outputs though.
outs = branching_op()
branch_1 = outs.branch_1
:ty-thankyou: 1
m

Mark Fickett

03/04/2022, 8:22 PM
Great, thanks for the explanation! (FIled a ticket about incorporating your explanation into the docs.)
a

alex

03/04/2022, 8:23 PM
perfect thanks for doing that