Skip to content

Commit 182ef91

Browse files
authored
Fix skipping fields with union of unsupported type (#722)
Fixes #721
1 parent e3e958e commit 182ef91

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

serde/compat.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,8 @@ def recursive(cls: TypeLike) -> None:
425425
stack.append(cls)
426426
if isinstance(cls, type):
427427
for f in dataclass_fields(cls):
428-
recursive(f.type)
428+
if not f.metadata.get("serde_skip"):
429+
recursive(f.type)
429430
stack.pop()
430431
elif is_opt(cls):
431432
args = type_args(cls)

tests/test_basics.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,7 @@ def __init__(self, value: int = 42) -> None:
867867
class Foo:
868868
name: str
869869
internal: UnsupportedClass = serde.field(default_factory=UnsupportedClass, skip=True)
870+
internal_union: UnsupportedClass | None = serde.field(default=None, skip=True)
870871

871872
# Serialization should work
872873
f = Foo(name="test")
@@ -876,6 +877,7 @@ class Foo:
876877
restored = serde.from_dict(Foo, {"name": "test"})
877878
assert restored.name == "test"
878879
assert isinstance(restored.internal, UnsupportedClass)
880+
assert restored.internal_union is None
879881

880882
# Also test with List of unsupported types
881883
@serde.serde

0 commit comments

Comments
 (0)