Skip to content

Commit

Permalink
Fixes catchall inheritance issue (#500)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonrock-a3 authored Nov 27, 2023
1 parent 968947c commit c26c3b9
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()

6 comments on commit c26c3b9

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
dataclasses_json
   cfg.py51492%80, 84–86
   core.py2601893%39–42, 52, 65, 67, 82, 84, 170, 198, 378–385, 389, 395
   mm.py2053085%33–36, 42–45, 53–56, 62–65, 88, 170–171, 176, 180, 184, 189, 193, 197, 205, 211, 216, 225, 230, 235, 244, 253–260
   stringcase.py25388%59, 76, 97
   undefined.py146299%25, 39
   utils.py1313673%12–25, 45–50, 61–65, 75, 100–101, 109–110, 125–133, 163, 182, 207
tests
   entities.py239399%22, 234, 240
   test_annotations.py814248%50–67, 78–102, 106–122
   test_api.py142497%88, 99, 139–140
   test_str_subclass.py22195%9
   test_union.py1311092%97–104, 118–125
TOTAL266015394% 

Tests Skipped Failures Errors Time
306 3 💤 0 ❌ 0 🔥 2.643s ⏱️

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
dataclasses_json
   cfg.py51492%80, 84–86
   core.py2591793%39–42, 52, 65, 67, 82, 84, 170, 378–385, 389, 395
   mm.py2042986%33–36, 42–45, 53–56, 62–65, 88, 170–171, 176, 180, 184, 189, 193, 197, 205, 211, 216, 225, 230, 235, 253–260
   stringcase.py25388%59, 76, 97
   undefined.py146299%25, 39
   utils.py1312978%12–25, 45–50, 61–65, 75, 100–101, 109–110, 163, 182, 207
tests
   entities.py239399%20, 234, 240
   test_annotations.py814248%50–67, 78–102, 106–122
   test_api.py142299%139–140
   test_str_subclass.py22195%9
TOTAL265813295% 

Tests Skipped Failures Errors Time
306 1 💤 0 ❌ 0 🔥 2.703s ⏱️

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
dataclasses_json
   cfg.py51492%80, 84–86
   core.py2601893%39–42, 52, 65, 67, 82, 84, 170, 198, 378–385, 389, 395
   mm.py2053085%33–36, 42–45, 53–56, 62–65, 88, 170–171, 176, 180, 184, 189, 193, 197, 205, 211, 216, 225, 230, 235, 244, 253–260
   stringcase.py25388%59, 76, 97
   undefined.py146299%25, 39
   utils.py1313673%12–25, 45–50, 61–65, 75, 100–101, 109–110, 125–133, 163, 182, 207
tests
   entities.py239399%22, 234, 240
   test_annotations.py814248%50–67, 78–102, 106–122
   test_api.py142497%88, 99, 139–140
   test_str_subclass.py22195%9
   test_union.py1311092%97–104, 118–125
TOTAL266015394% 

Tests Skipped Failures Errors Time
306 3 💤 0 ❌ 0 🔥 2.696s ⏱️

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
dataclasses_json
   cfg.py51492%80, 84–86
   core.py2601793%39–42, 52, 65, 67, 82, 84, 170, 378–385, 389, 395
   mm.py2042986%33–36, 42–45, 53–56, 62–65, 88, 170–171, 176, 180, 184, 189, 193, 197, 205, 211, 216, 225, 230, 235, 253–260
   stringcase.py25388%59, 76, 97
   undefined.py144299%25, 39
   utils.py1312978%12–25, 45–50, 61–65, 75, 100–101, 109–110, 163, 182, 207
tests
   entities.py218399%20, 234, 240
   test_annotations.py804248%50–67, 78–102, 106–122
   test_api.py140299%139–140
   test_str_subclass.py22195%9
TOTAL253613295% 

Tests Skipped Failures Errors Time
306 1 💤 0 ❌ 0 🔥 2.672s ⏱️

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
dataclasses_json
   cfg.py51492%80, 84–86
   core.py2591793%39–42, 52, 65, 67, 82, 84, 170, 378–385, 389, 395
   mm.py2042986%33–36, 42–45, 53–56, 62–65, 88, 170–171, 176, 180, 184, 189, 193, 197, 205, 211, 216, 225, 230, 235, 253–260
   stringcase.py25388%59, 76, 97
   undefined.py146299%25, 39
   utils.py1312978%12–25, 45–50, 61–65, 75, 100–101, 109–110, 163, 182, 207
tests
   entities.py239399%22, 234, 240
   test_annotations.py814248%50–67, 78–102, 106–122
   test_api.py142199%139
   test_str_subclass.py22195%9
TOTAL265813195% 

Tests Skipped Failures Errors Time
306 1 💤 0 ❌ 0 🔥 2.799s ⏱️

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
dataclasses_json
   cfg.py51492%80, 84–86
   core.py2601893%39–42, 52, 65, 67, 82, 84, 170, 198, 378–385, 389, 395
   mm.py2053085%33–36, 42–45, 53–56, 62–65, 88, 170–171, 176, 180, 184, 189, 193, 197, 205, 211, 216, 225, 230, 235, 244, 253–260
   stringcase.py25388%59, 76, 97
   undefined.py146299%25, 39
   utils.py1313673%12–25, 45–50, 61–65, 75, 100–101, 109–110, 125–133, 163, 182, 207
tests
   entities.py239399%22, 234, 240
   test_annotations.py814248%50–67, 78–102, 106–122
   test_api.py142497%88, 99, 139–140
   test_str_subclass.py22195%9
   test_union.py1311092%97–104, 118–125
TOTAL266015394% 

Tests Skipped Failures Errors Time
306 3 💤 0 ❌ 0 🔥 4.613s ⏱️

Please sign in to comment.