Hello! I try to run one of the example in the docu...
# ask-community
j
Hello! I try to run one of the example in the documentation about "Union types" from "Advanced config types" for dagster 1.3.1
Copy code
from 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.
Copy code
>       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?
c
was able to reproduce this error - I think this snippet is broken. Making an issue -we’ll get this resolved as soon as possible. cc @ben mind providing some guidance on workarounds in the near term?
b
Hi Jueming, thanks for the report - it looks like this issue happens when constructing from
Config
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.
Copy code
ConfigWithUnion(pet={"cat": {"meows": 10}})
j
Perfect. Thanks for the help!