Stephen Bailey
04/25/2023, 2:57 PM__post_init_post_parse__
in pydantic resources? my use case is that i want to construct a client property on the resource, but only want to supply the secrets. here's what i expect to be able to do:
from dagster import asset, materialize, ConfigurableResource
class FooResource(ConfigurableResource):
api_key = "foo"
def __post_init_post_parse__(self):
self.client = get_client(self.api_key)
@asset
def thing(context, foo: FooResource):
foo.client.do_something()
result = materialize([thing], resources={"foo": FooResource(api_key="test")})
print(result)
Vinnie
04/25/2023, 3:35 PMclass UtilsS3IOManager(ConfigurableIOManager):
class Config:
extra = "allow"
frozen = False
bucket: str
@property
def s3(self):
if not hasattr(self, "_s3"):
self._s3 = construct_s3_client()
return self._s3
Stephen Bailey
04/25/2023, 4:34 PMclass DatadogApiResource(ConfigurableResource):
api_key: str
app_key: str
@property
def client(self):
if not hasattr(self, "_client"):
self._client = self.get_client()
return self._client
i get this:
dagster._core.errors.DagsterInvalidInvocationError: 'DatadogApiResource' is a Pythonic resource and does not support manipulating undeclared attribute '_client' as it inherits from 'pydantic.BaseModel' without extra="allow". If trying to maintain state on this resource, consider building a separate, stateful client class, and provide a method on the resource to construct and return the stateful client.
Vinnie
04/25/2023, 5:05 PMclass Config
block with the extra
and frozen
params as I sent to make sure the Resources aren’t frozenStephen Bailey
04/25/2023, 6:04 PMAndras Somi
04/25/2023, 6:08 PMDaniel Vetter
04/25/2023, 6:13 PMVinnie
04/25/2023, 6:14 PMschrockn
04/25/2023, 7:11 PMben
04/27/2023, 8:12 PM