https://dagster.io/ logo
#ask-community
Title
# ask-community
m

Manish Khatri

08/29/2023, 5:01 PM
Hi wave anim I’m creating my own resource by extending the
ConfigurableResource
. As per the Dagster docs, this means the new resource implements
ResourceDefinition
Copy code
class MyResource(ConfigurableResource)
However, when passing the resource to a graph, mypy complains that the resource passed across is an incompatible type
Copy code
my_resource = MyResource(...)

my_graph.to_job(
    name="my_job",
    resource_defs={
        "my_resource": my_resource,  # of type MyResource
    },
)
The mypy output:
Copy code
Argument "my_resource" to "my_job" has incompatible type "MyResource"; expected "ResourceDefinition"
Can anyone advise how this can be resolved? Using
dagster==1.4.6
o

Odette Harary

08/29/2023, 5:40 PM
try:
Copy code
my_graph.to_job(
    name="my_job",
    resource_defs={
        "my_resource": MyResource,  # of type MyResource
    },
)
m

Manish Khatri

08/29/2023, 5:41 PM
Hi Odette, in my example.
my_resource
is already a constructed
MyResource
. E.g.:
Copy code
my_resource = MyResource(...)
o

Odette Harary

08/29/2023, 5:47 PM
gotcha - let me take a look
q

Quang Hanh Nguyen

09/26/2023, 2:06 PM
I’m having the same issue, I think this is a bug. Basically
ConfigurableResource
objects fail the
isinstance
check with type
ResourceDefinition
, as opposed to what says in the doc https://docs.dagster.io/_apidocs/resources#dagster.ConfigurableResource
This class is a subclass of both
ResourceDefinition
and
Config
.
Example:
Copy code
>>> from dagster import ConfigurableResource, ResourceDefinition
>>> class MyResource(ConfigurableResource):
...     name: str
... 
>>> my_resource = MyResource(name="abc")
>>> isinstance(my_resource, ResourceDefinition)
False