Skip to content

v2.4

Choose a tag to compare

@Fatal1ty Fatal1ty released this 22 Apr 12:40
· 979 commits to master since this release

Changes

  • Fixed calling to_dict method of a class that doesn't have omit_none and by_alias keyword arguments added in case it has a field of the type that has these arguments added:
@dataclass
class A(DataClassDictMixin):
    x: Optional[int] = None

    class Config(BaseConfig):
        aliases = {"x": "x_alias"}
        code_generation_options = [
            TO_DICT_ADD_OMIT_NONE_FLAG,
            TO_DICT_ADD_BY_ALIAS_FLAG,
        ]

@dataclass
class B(DataClassDictMixin):
    a: Optional[A] = None

# This caused an exception NameError: name 'omit_none' is not defined
print(B(a=A(1)).to_dict())