Ryan
02/02/2021, 3:29 PMdagster_type_loader
to map a string value from the config to a domain Enum, using the basic MyEnum[choice_name]
. I was expecting that any errors thrown from type loader functions (in this case a KeyError
whenever an invalid enum name is specified) would result in a "Type check failed" event, but I see that the exception just propagates and breaks the pipeline at that point.
Is there anything I can do to have invalid inputs to type loader functions handled slightly more gracefully within the framework? Something like:
@dagster_type_loader(str)
def load_my_enum(_, choice_name: str):
try:
return MyEnum[choice_name]
except KeyError as ex:
raise DagsterSpeciallyHandledError()
I tried with DagsterInvalidConfigError
but it didn't seem ergonomic to use from this context.alex
02/02/2021, 4:11 PM@dagster_type_loader(str)instead of taking an arbitrary
str
in config space, you could define an enum
from dagster import Enum
@dagster_type_loader(Enum.from_python_enum(MyEnum))
sandy
02/02/2021, 4:26 PMRyan
02/02/2021, 6:02 PMfrom dagster import Enum, dagster_type_loader
DagsterMyEnum = Enum.from_python_enum(MyEnum)
@dagster_type_loader(DagsterMyEnum)
def load_my_enum(_, choice: DagsterMyEnum):
return MyEnum[choice.name]
This way, in my parameterised tests, I can consistently get a DagsterInvalidConfigError
whether I pass it a string key that's not valid, or another data type altogether 👍🏼dagster_type_loader
. It wasn't necessarily that the pipeline should be able to proceed, just that I'd like to be able to express to the pipeline (I was thinking via some agreed exception type) that the conversion from the config value to my target type has failed in a way that Dagster understands, e.g. InvalidConfig
.
Then, by "graceful" I just meant that the pipeline would actually be able to finish as it normally would with an invalid input (i.e. early) and then I'd be able to check the return value of execute_solid
to investigate what happened. Of course if a non-Dagster exception bubbles up then fine to explode immediately 🧨sandy
02/02/2021, 7:30 PM