()
| 59 | |
| 60 | |
| 61 | def test_serialize_extra_allow_subclass_2() -> None: |
| 62 | class Parent(BaseModel): |
| 63 | x: int |
| 64 | model_config = ConfigDict(extra='allow') |
| 65 | |
| 66 | class Child(Parent): |
| 67 | y: int |
| 68 | |
| 69 | class Model(BaseModel): |
| 70 | inner: Parent |
| 71 | |
| 72 | m = Model(inner=Child(x=1, y=2)) |
| 73 | assert m.inner.y == 2 |
| 74 | assert m.model_dump() == {'inner': {'x': 1}} |
| 75 | assert json.loads(m.model_dump_json()) == {'inner': {'x': 1}} |
| 76 | |
| 77 | m = Model(inner=Parent(x=1, y=2)) |
| 78 | assert m.inner.y == 2 |
| 79 | assert m.model_dump() == {'inner': {'x': 1, 'y': 2}} |
| 80 | assert json.loads(m.model_dump_json()) == {'inner': {'x': 1, 'y': 2}} |
| 81 | |
| 82 | |
| 83 | def test_serializer_annotated_plain_always(): |
nothing calls this directly
no test coverage detected