[BUG] Empty BackLink for Optional[BackLink[ADoc]]
when document has no back-link
#920
Labels
Optional[BackLink[ADoc]]
when document has no back-link
#920
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: