Open tuxiano opened 1 month ago
Hey @tuxiano - there are two problems with this code.
First, your graph doesn't have inputs, but your op does, causing problems when you call execute_in_progress
, because the parameter input_values
would be required.
Second, if you want to define assets as upstream dependencies for a graph, I would recommend using a graph-backed asset instead, where you can leverage an op while using assets.
This works:
from dagster import (
Definitions,
In,
Out,
asset,
define_asset_job,
graph_asset,
materialize_to_memory,
op,
)
def test_graph():
@asset
def asset_1() -> int:
return 1
@asset
def asset_2() -> int:
return 2
# Define the op that takes multiple inputs
@op(
ins={
"input_1": In(),
"input_2": In(),
},
out=Out(int),
)
def combine_inputs(context, input_1: int, input_2: int) -> int:
context.log.info("Hello, world!")
return input_1 + input_2
# Define the graph that calls the op
@graph_asset
def my_graph(asset_1, asset_2):
return combine_inputs(asset_1, asset_2)
# Define the assets and job in a Definitions object
defs = Definitions(assets=[asset_1, asset_2, my_graph])
# Test materializing the assets
result = materialize_to_memory([asset_1, asset_2, my_graph])
assert result.success
# Test executing a job
my_job = define_asset_job("my_graph_job", selection=["asset_1", "asset_2", "my_graph"]).resolve(
asset_graph=defs.get_repository_def().asset_graph
)
result = my_job.execute_in_process()
assert result.success
Dagster version
1.8.5
What's the issue?
I try to pass an assets to an op through a graph, but dagster complains that:
Attempting to access run_id, but it was not provided when constructing the OutputContex
What did you expect to happen?
I would expect, that it is a rather straight forward task to pass assets as input to an op, but I'm struggling
How to reproduce?
I created a pytest, which should provide all the needed information:
Deployment type
Local
Deployment details
I use a local installation with python 3.11 and the latest dagster os edition.
Additional information
Full error message:
Message from the maintainers
Impacted by this issue? Give it a 👍! We factor engagement into prioritization.