I must be missing something obvious. The <document...
# ask-community
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
def test_op(context: OpExecutionContext, test: str) -> int:
    <http://context.log.info|context.log.info>(f"test op {test}")
    return 42

def test_asset() -> int:
    return test_op("test")
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
What happens if you modify the asset function definition to include
Copy code
def test_asset(context: OpExecutionContext):
    return test_op("test") # might need to pass in context explicitly
Hi! Ops can't be executed within assets. The mental model is that the
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
-decorated function, then you can remove the
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
decorator instead of the
🙏 2
Thanks @Tim Castillo, knew I was misunderstanding something basic here.