Describe the bug
tests/test_fastapi/test_fastapi_usage.py::test_read_main fails with Pydantic 2.13.
To Reproduce
In a clone of ormar:
poetry install -E all
- `poetry add 'pydantic>=2.13'
.venv/bin/pytest tests/test_fastapi/test_fastapi_usage.py -vv
FAILED tests/test_fastapi/test_fastapi_usage.py::test_read_main - AssertionError: assert {'id': 1, 'name': 'test', 'category': {'id': None, 'name': 'test cat'}} == {'category': {'id': None, 'items': [{'category': {'id': None, 'name': 'test cat'}, 'id': 1, 'name': 'test'}], 'name': 'test cat'}, 'id': 1, 'name': 'test'}
Common items:
{'id': 1, 'name': 'test'}
Differing items:
{'category': {'id': None, 'name': 'test cat'}} != {'category': {'id': None, 'items': [{'category': {'id': None, 'name': 'test cat'}, 'id': 1, 'name': 'test'}], 'name': 'test cat'}}
Full diff:
{
'category': {
'id': None,
- 'items': [
- {
- 'category': {
- 'id': None,
- 'name': 'test cat',
- },
- 'id': 1,
- 'name': 'test',
- },
- ],
'name': 'test cat',
},
'id': 1,
'name': 'test',
}
Expected behavior
Passing tests.
Versions (please complete the following information):
All versions as in current poetry.lock, except for pydantic-core 2.46.4 and pydantic 2.13.4.
Additional context
I realize that this isn't what the Poetry lock file specifies, but Debian unstable currently has pydantic 2.13.3 and we're running into this in distribution-wide tests there. It's also visible in #1660.
I tracked this down as far as pydantic.type_adapter.TypeAdapter.dump_json. Setting a breakpoint there, I find that instance is something along the lines of Item({'id': 1, 'name': 'test', 'category': Category({'id': None, 'name': 'test cat', 'items': [<weakproxy at 0x7f92342dbf60; to 'tests.test_fastapi.test_fastapi_usage.Item' at 0x7f92342e04b0>]})}). pydantic 2.12.5 serializes this as ormar's tests expect, but pydantic 2.13.4 drops the items. But I'm not sure whether this is because of a change in the handling of weakref proxies, or because something is different about the instance's pydantic metadata. Hopefully you can figure it out?
Describe the bug
tests/test_fastapi/test_fastapi_usage.py::test_read_mainfails with Pydantic 2.13.To Reproduce
In a clone of ormar:
poetry install -E all.venv/bin/pytest tests/test_fastapi/test_fastapi_usage.py -vvExpected behavior
Passing tests.
Versions (please complete the following information):
All versions as in current
poetry.lock, except forpydantic-core2.46.4 andpydantic2.13.4.Additional context
I realize that this isn't what the Poetry lock file specifies, but Debian unstable currently has
pydantic2.13.3 and we're running into this in distribution-wide tests there. It's also visible in #1660.I tracked this down as far as
pydantic.type_adapter.TypeAdapter.dump_json. Setting a breakpoint there, I find thatinstanceis something along the lines ofItem({'id': 1, 'name': 'test', 'category': Category({'id': None, 'name': 'test cat', 'items': [<weakproxy at 0x7f92342dbf60; to 'tests.test_fastapi.test_fastapi_usage.Item' at 0x7f92342e04b0>]})}).pydantic2.12.5 serializes this asormar's tests expect, butpydantic2.13.4 drops theitems. But I'm not sure whether this is because of a change in the handling of weakref proxies, or because something is different about the instance'spydanticmetadata. Hopefully you can figure it out?