I must be missing something obvious. The <document...
# ask-community
s
I must be missing something obvious. The documentation says
Copy code
When 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:
Copy code
@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:
Copy code
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?
🤖 1
j
What happens if you modify the asset function definition to include
context
?
Copy code
@asset
def test_asset(context: OpExecutionContext):
    return test_op("test") # might need to pass in context explicitly
t
Hi! Ops can't be executed within assets. The mental model is that the
@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
decorator
🙏 2
s
Thanks @Tim Castillo, knew I was misunderstanding something basic here.