Closed RobertoBochet closed 7 months ago
Hi! Thank you for the catch. I'll check and fix it this/next week.
Hi @RobertoBochet , Sorry for the late reply. It looks like you have a typo in word "alias". You use "alis"
Here is fixed version. It looks like it works. Please try:
import asyncio
from typing import Annotated
from motor.motor_asyncio import AsyncIOMotorClient
from pydantic import Field
from beanie import init_beanie, Document, Link
class C(Document):
a: Annotated[str, Field(alias="_a")] = 'f'
class D(Document):
c: Link[C]
async def main():
client = AsyncIOMotorClient("mongodb://beanie:beanie@localhost:27017")
db = client.beanie_test
await init_beanie(database=db, document_models=[C, D])
c = C()
await c.save()
c = await C.get(c.id)
d = D(c=c)
await d.save()
d = await D.get(d.id)
await d.fetch_all_links()
print(d)
print(d.c.a)
print(d.model_dump(by_alias=True))
asyncio.run(main())
This issue is stale because it has been open 30 days with no activity.
This issue was closed because it has been stalled for 14 days with no activity.
Describe the bug Hi, another bug related to migration to pydantic v2. In the case you have a
Document
with a field of typeLink
to anotherDocument
, when you try to perform amodel_dump
of the rootDocument
requiring the use of the alias this directive is applied only for the rootDocument
To Reproduce
This results in
Expected behavior The example above should return
Additional context
In FastAPI this bug prevents the use of
Link
in the response modelsThank so much for your work