You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Hi, I'm using FastAPI and Beanie and I have to set of models, one using Beanie for database and other one for API schema. The database has two documents Employee and Department that are linked :
Since I'm using FastAPI, when I return a data instance, it tries to convert from db to schema (using pydantic method Model.model_validate(v,from_attributes=True)).
Everything works just fine until I try to get an employee that no Department is linked to. Then Employee.department field is an empty BackLink that is not validate or processable for pydantic so it raises a Validation Error:
Expected behavior
for fields of type Optional[BackLink[ADoc]] set/return None when there is no back-link.
The text was updated successfully, but these errors were encountered:
b-simjoo
changed the title
[BUG] Empty BackLink for Optional[BackLink[...]] when document has no back-link
[BUG] Empty BackLink for Optional[BackLink[ADoc]] when document has no back-link
Apr 21, 2024
Describe the bug
Hi, I'm using FastAPI and Beanie and I have to set of models, one using Beanie for database and other one for API schema. The database has two documents
Employee
andDepartment
that are linked :On the other side I have proper Models for both:
Since I'm using FastAPI, when I return a data instance, it tries to convert from db to schema (using pydantic method
Model.model_validate(v,from_attributes=True)
).Everything works just fine until I try to get an employee that no Department is linked to. Then
Employee.department
field is an emptyBackLink
that is not validate or processable for pydantic so it raises a Validation Error:Expected behavior
for fields of type
Optional[BackLink[ADoc]]
set/returnNone
when there is no back-link.The text was updated successfully, but these errors were encountered: