Reported via https://github.com/pydantic/pydantic/issues/9590.
()
| 2162 | @pytest.mark.thread_unsafe(reason='Passes on multithreaded. This needs to be investigated further.') |
| 2163 | @pytest.mark.xfail(reason='Waiting for union serialization fixes via https://github.com/pydantic/pydantic/issues/9688.') |
| 2164 | def test_discriminated_union_serializer() -> None: |
| 2165 | """Reported via https://github.com/pydantic/pydantic/issues/9590.""" |
| 2166 | |
| 2167 | @dataclass |
| 2168 | class FooId: |
| 2169 | _id: int |
| 2170 | |
| 2171 | @dataclass |
| 2172 | class BarId: |
| 2173 | _id: int |
| 2174 | |
| 2175 | FooOrBarId = Annotated[ |
| 2176 | Annotated[FooId, PlainSerializer(lambda v: {'tag': 'foo', '_id': v._id}), Tag('foo')] |
| 2177 | | Annotated[BarId, PlainSerializer(lambda v: {'tag': 'bar', '_id': v._id}), Tag('bar')], |
| 2178 | Discriminator(lambda v: v['tag']), |
| 2179 | ] |
| 2180 | |
| 2181 | adapter = TypeAdapter(FooOrBarId) |
| 2182 | assert adapter.dump_python(FooId(1)) == {'tag': 'foo', '_id': 1} |
| 2183 | assert adapter.dump_python(BarId(2)) == {'tag': 'bar', '_id': 2} |
| 2184 | |
| 2185 | |
| 2186 | def test_deferred_discriminated_union_meta_key_removed() -> None: |
nothing calls this directly
no test coverage detected