Skip to content

Commit

Permalink
Merge branch 'master' into fix-builtins-subclass
Browse files Browse the repository at this point in the history
  • Loading branch information
george-zubrienko authored Dec 13, 2023
2 parents 038b893 + c26c3b9 commit 8b31b5e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dataclasses_json/undefined.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def _get_default(catch_all_field: Field) -> Any:
@staticmethod
def handle_to_dict(obj, kvs: Dict[Any, Any]) -> Dict[Any, Any]:
catch_all_field = \
_CatchAllUndefinedParameters._get_catch_all_field(obj)
_CatchAllUndefinedParameters._get_catch_all_field(obj.__class__)
undefined_parameters = kvs.pop(catch_all_field.name)
if isinstance(undefined_parameters, dict):
kvs.update(
Expand Down
20 changes: 19 additions & 1 deletion tests/test_undefined_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,4 +383,22 @@ class UnknownAPIDumpDefault:
catch_all: CatchAll = field(default_factory=dict)

dump = UnknownAPIDumpDefault(**valid_response)
assert dump.catch_all == {}
assert dump.catch_all == {}


def test_undefined_inheritance():
@dataclass_json(undefined=Undefined.INCLUDE)
@dataclass
class TestInternalConfig:
options: CatchAll = None
val: str = "bar"
val2: int = 0

@dataclass_json
@dataclass
class TestInternalExtendConfig(TestInternalConfig):
val: str = "baz"

tie = TestInternalExtendConfig()
tie.to_dict()

0 comments on commit 8b31b5e

Please sign in to comment.