Sean Quinlan
07/05/2023, 6:30 PMWhen writing an op, users can optionally provide a first parameter, context. When this parameter is supplied, Dagster will supply a context object to the body of the op.
I have a test asset defined with a test op:
@op
def test_op(context: OpExecutionContext, test: str) -> int:
<http://context.log.info|context.log.info>(f"test op {test}")
return 42
@asset
def test_asset() -> int:
return test_op("test")
Materializing test_asset
fails with:
dagster._core.errors.DagsterInvalidInvocationError: Compute function of op 'test_op' has context argument, but no context was provided when invoking.
What am I doing wrong here?Justin Taylor
07/05/2023, 6:41 PMcontext
?
@asset
def test_asset(context: OpExecutionContext):
return test_op("test") # might need to pass in context explicitly
Tim Castillo
07/05/2023, 6:49 PM@asset
decorator is:
• trust this function will produce an asset
• the function body is an Op that produces this asset
So trying to execute an individual Op within that function body breaks that model.
If you'd like to run a function within an @asset
-decorated function, then you can remove the @op
decorator and use the function as a normal python fn.
If you'd like to run this Op on its own, you can write it in a job and execute that job.
And in the advanced use cases, you may want to use Ops to produce assets. To get this granular control, you'd use the @graph_asset
decorator instead of the @asset
decoratorSean Quinlan
07/05/2023, 6:51 PM