Jueming Liu
04/24/2023, 3:59 PMfrom dagster import asset, materialize, Config, RunConfig
from pydantic import Field
from typing import Union
from typing_extensions import Literal
class Cat(Config):
pet_type: Literal["cat"] = "cat"
meows: int
class Dog(Config):
pet_type: Literal["dog"] = "dog"
barks: float
class ConfigWithUnion(Config):
pet: Union[Cat, Dog] = Field(discriminator="pet_type")
config = ConfigWithUnion(pet=Cat(meows=10))
However, I got following error which I'm not sure if it's a bug or I did't use it correctly.
> config = ConfigWithUnion(pet=Cat(meows=10))
test_ops.py:64:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../../../.venv/app_prediction_venv/lib/python3.10/site-packages/dagster/_config/pythonic_config/__init__.py:176: in __init__
nested_items = list(check.is_dict(value).items())
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
obj = Cat(pet_type='cat', meows=10), key_type = None, value_type = None
additional_message = None
def is_dict(
obj: object,
key_type: Optional[TypeOrTupleOfTypes] = None,
value_type: Optional[TypeOrTupleOfTypes] = None,
additional_message: Optional[str] = None,
) -> Dict:
if not isinstance(obj, dict):
> raise _type_mismatch_error(obj, dict, additional_message)
E dagster._check.CheckError: Object Cat(pet_type='cat', meows=10) is not a dict. Got Cat(pet_type='cat', meows=10) with type <class 'app_backtest_tests.test_ops.test_simple.<locals>.Cat'>.
../../../../.venv/app_prediction_venv/lib/python3.10/site-packages/dagster/_check/__init__.py:434: CheckError
Any ideas?chris
04/24/2023, 9:58 PMben
04/24/2023, 10:16 PMConfig
objects, but not a config dictionary.
I’ve put up a fix for this issue that we should be able to get released this week. Runtime configuration (e.g. through the launchpad) should still work, as should config using unstructured dictionary input, e.g.
ConfigWithUnion(pet={"cat": {"meows": 10}})
Jueming Liu
04/25/2023, 6:32 PM