Why is it that `@op`s cannot see resources like `@...
# ask-community
c
Why is it that `@op`s cannot see resources like
@assets
can? For example, this works fine:
Copy code
@asset(required_resource_keys={"snowflake"})
def my_thing(context: OpExecutionContext) -> None:
    return
but this does not work, even when right next to assets
Copy code
@op(required_resource_keys={"snowflake"})
def my_thing(context: OpExecutionContext) -> None:
    return
and the error is
Copy code
dagster._core.errors.DagsterInvalidDefinitionError: resource with key 'snowflake' required by op 'my_thing' was not provided. Please provide a <class 'dagster._core.definitions.resource_definition.ResourceDefinition'> to key 'snowflake', or change the required key to one of the following keys which points to an <class 'dagster._core.definitions.resource_definition.ResourceDefinition'>: ['io_manager']
l
I've understood it as an
@op
is not independently usable i.e. it needs to be utilized from a
@job
which in turn provide the resource definitions. Look at your Definition, the assets are included but ops are not. If assets aren't included in the Definition they wouldn't see the configured resources either.
c
That's not very clear with the examples in the documentation, but makes sense. So, I would to do something like:
Copy code
@op(required_resource_keys={"snowflake"})
def my_thing(context: OpExecutionContext) -> None:
    return

@job(required_resource_keys={"snowflake"})
def my_job():
    my_thing()
and then @job will expose the resource to the @op?
l
You'd define the resources in the
@job
decorator similar to how you would supply them to a Definition, like this:
Copy code
@op(required_resource_keys={"snowflake"})
def my_thing(context: OpExecutionContext) -> None:
    return

@job(resource_defs={"snowflake": snowflake_io_manager...})
def my_job():
    my_thing()
c
ah, ok. That seems kind of redundant, but works for me. 🙂
l
If you follow the full-featured example, it would be the "resource by stage" dict; you can re-use that resource block in
Definition()
or
@job()
❤️ 1