Is it possible to create an asset using `from_grap...
# ask-community
d
Is it possible to create an asset using
from_graph
and have that asset accept op configs? Or, as an alternative question, what's the right process for providing input variables that are used persistently throughout the graph? My previous use pattern was to define very simple ops that took a config and returned its value and then pass these ops as inputs. What's the correct pattern in asset world? Thanks for your patience with all my questions.
c
Hi Dmitry. When you define regular ops you can specify a config schema and wrap these ops in a graph. Then, you can pass run config to your job execution. In the asset world, this remains the same, you can do something like:
Copy code
@op(config_schema=int)
def op_one(context):
    assert context.op_config == 1
    return context.op_config


@op(config_schema=int)
def op_two(context, op_one):
    assert context.op_config == 2
    return context.op_config + op_one


@graph
def my_graph():
    return op_two(op_one())


materialize_to_memory(
    [AssetsDefinition.from_graph(my_graph)],
    run_config={"ops": {"my_graph": {"ops": {"op_one": {"config": 1}, "op_two": {"config": 2}}}}},
)
s
@Dmitry Mogilevsky if your goal is to share config across a bunch of ops, our typical recommendation is to use a resource: https://docs.dagster.io/concepts/configuration/config-schema#passing-configuration-to-multiple-ops-in-a-job