Skip to content

Commit 2a806ad

Browse files
authored
Add regression test for MISSING sentinel serialization with subclasses (#13048)
1 parent 12e54df commit 2a806ad

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

tests/test_missing_sentinel.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,26 @@ class Model(BaseModel):
118118
'anyOf': [{'anyOf': [{'type': 'integer'}, {'type': 'string'}], 'ge': 1}, {'type': 'null'}],
119119
'title': 'F4',
120120
}
121+
122+
123+
def test_missing_sentinel_child_fields() -> None:
124+
"""https://github.com/pydantic/pydantic/issues/13001."""
125+
126+
class Base(BaseModel, extra='forbid'):
127+
base_field: Union[str, MISSING] = MISSING
128+
129+
class Parent(Base):
130+
parent_field: str
131+
132+
class Child(Parent):
133+
child_field: str
134+
135+
class Container(BaseModel, extra='forbid'):
136+
item: Union[Parent, MISSING] = MISSING
137+
138+
child = Child(parent_field='p', child_field='c')
139+
container = Container(item=child)
140+
141+
result = TypeAdapter(Container).dump_python(container)
142+
143+
assert result == {'item': {'parent_field': 'p'}}

0 commit comments

Comments
 (0)