From c26c3b9e6379fd89cc8e5b6d5d5b75ac4370352f Mon Sep 17 00:00:00 2001 From: jasonrock-a3 <107961397+jasonrock-a3@users.noreply.github.com> Date: Mon, 27 Nov 2023 11:44:00 -0800 Subject: [PATCH] Fixes catchall inheritance issue (#500) --- dataclasses_json/undefined.py | 2 +- tests/test_undefined_parameters.py | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/dataclasses_json/undefined.py b/dataclasses_json/undefined.py index d896bb79..cb8b2cfc 100644 --- a/dataclasses_json/undefined.py +++ b/dataclasses_json/undefined.py @@ -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( diff --git a/tests/test_undefined_parameters.py b/tests/test_undefined_parameters.py index 58740dcb..bac711af 100644 --- a/tests/test_undefined_parameters.py +++ b/tests/test_undefined_parameters.py @@ -383,4 +383,22 @@ class UnknownAPIDumpDefault: catch_all: CatchAll = field(default_factory=dict) dump = UnknownAPIDumpDefault(**valid_response) - assert dump.catch_all == {} \ No newline at end of file + 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() +