I'm trying to follow this section <https://docs.da...
# ask-community
y
I'm trying to follow this section https://docs.dagster.io/concepts/resources#accessing-resources-in-ops for accessing resources in ops with the following code:
Copy code
from dagster import job, op, Definitions

@op(required_resource_keys={"database"})
def op_requires_resources(context):
    database_resource = context.resources.database
    <http://context.log.info|context.log.info>(database_resource)

@job()
def demo_job():
    op_requires_resources()

defs = Definitions(
    jobs=[demo_job],
    resources={
        "database": "test_resource",
    }
)
however, I'm getting the following error:
Copy code
dagster._core.errors.DagsterInvalidDefinitionError: resource with key 'database' required by op 'op_requires_resources' was not provided. Please provide a <class 'dagster._core.definitions.resource_definition.ResourceDefinition'> to key 'database', or change the required key to one of the following keys which points to an <class 'dagster._core.definitions.resource_definition.ResourceDefinition'>: ['io_manager']
what am I doing wrong here?
dagster bot responded by community 1
🤖 1
t
You need to define the resource e.g. by decorating a function
@resource
def test_resource(init_context):
...
y
thanks @Terry Lines
@Terry Lines how do i get the resources from:
Copy code
defs = Definitions(
    jobs=[demo_job],
    resources={
        "database": "test_resource",
    }
)
in:
@resource
def test_resource(init_context):
t
Try replacing "test_resource" in your definitions with ResourceDefinition.hardcoded_resource("test_resource"). Then replace it with test_resource (object not string) and define a more complex resource in a function as I mentioned. This is also a ResourceDefinition. In the Definitions you are linking a ResourceDefinition with a key in the resources dictionary. You then define a op which makes reference to the key. The purpose of this all is so that if you want to use different resources, you don't have to rewrite the op.