Hi! Is there an option to use non_argument_deps wi...
# ask-community
y
Hi! Is there an option to use non_argument_deps with OR logic? E.g., to run an asset op if one of its dependencies was rematerialized?
c
Hi Yevhen. Unfortunately there is no way to use
non_argument_deps
with OR logic. One workaround I can think of will come out in
0.15.0
(released next week). In that release, you'll be able to wrap a graph with an assets definition. Within your graph, you can do something like the following:
Copy code
@op(out={"result": Out(dagster_type=Optional[int], is_required=False)})
def conditional_op():
    if random.randint(0, 1) == 0:
        yield Output(3, output_name="result")


@op
def maybe_skips_op(merged_inputs):
    return 3


@graph(
    out={
        "asset_1": GraphOut(),
        "asset_2": GraphOut(),
        "asset_3": GraphOut(),
    }
)
def graph_asset():
    first_asset = conditional_op()
    second_asset = conditional_op()
    third_asset = maybe_skips_op([first_asset, second_asset])
    return {
        "asset_1": first_asset,
        "asset_2": second_asset,
        "asset_3": third_asset,
    }


my_job = build_assets_job("my_job", assets=[AssetsDefinition.from_graph(graph_asset)])
Defining ops with optional outputs will allow you to conditionally materialize assets. Typically, if any input op does not yield an output, the downstream op will skip execution. You can bypass this by passing a list of op outputs into a downstream op (so the op will execute if either output exists).
🪐 1
y
Thank you! I think I'll use the second approach.