New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Beanie projection and Pydantic Schema do not play well together #892
Comments
To give more context, here is my dirty fix on fastapi. I’m really not satisfied with that but that’s all I could find:
|
I can post a gist in a bit, but I use a base class that overrides the BaseModel and handles the _id conversion there, both directions. Otherwise lots of ways to tackle this, most are so-so, but more of a pydantic quirk than anything else I think! |
@CartfordSam That would be nice thank you! |
In FastAPI you can use That way, you don't even need a projection if the only purpose for it is to ensure you have @app.get("/hack", response_model=list[Author], response_model_by_alias=False)
async def hack() -> list[Any]:
return await Author.find_all().to_list() |
Thanks, I misunderstood what it was doing, it seems to work indeed. Then i suppose using the format that works for projection is suitable. |
yeah complexify is right lol |
Describe the bug
Beanie projections are expecting an "_id" field, but Pydantic schema expect "id". This makes it impossible to use the same Schema and create duplicated code (unless I’m missing the proper method to do it)
To Reproduce
Expected behavior
A way to use the same Schema for projections, like mapping _id to id during projection
The text was updated successfully, but these errors were encountered: