Hi all. I want to use a `dagster_type_loader` to ...
# announcements
Hi all. I want to use a
to map a string value from the config to a domain Enum, using the basic
. I was expecting that any errors thrown from type loader functions (in this case a
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:
Copy code
def load_my_enum(_, choice_name: str):
       return MyEnum[choice_name]
    except KeyError as ex:
        raise DagsterSpeciallyHandledError()
I tried with
but it didn't seem ergonomic to use from this context.
instead of taking an arbitrary
in config space, you could define an enum
Copy code
from dagster import Enum

this would cause invalid values to fail at config validation time
@Ryan - when you say you'd like the error to be handled gracefully, what behavior would you ideally like to happen following the invalid input? E.g. would you like the pipeline to be able to proceed with some sort of fallback value?
Fab, thanks a lot @alex, that's got me where I wanted to be:
Copy code
from dagster import Enum, dagster_type_loader

DagsterMyEnum = Enum.from_python_enum(MyEnum)

def load_my_enum(_, choice: DagsterMyEnum):
    return MyEnum[choice.name]
This way, in my parameterised tests, I can consistently get a
whether I pass it a string key that's not valid, or another data type altogether ๐Ÿ‘๐Ÿผ
Hey @sandy ๐Ÿ™‚ It's basically a question of the API of
. 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.
. 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
to investigate what happened. Of course if a non-Dagster exception bubbles up then fine to explode immediately ๐Ÿงจ
Hope that makes sense!
Thanks Ryan - that makes total sense