Closed agrin96 closed 1 year ago
Of course I spent several hours trying to figure this out and after I posted a bug report I figured it out. Let this be a warning for anyone who works with motor + pydantic
and then switches to beanie + pydantic
.
Somehow, the object ids created by the two are different even though they look exactly the same. I discovered that any users I created using my old motor method did not show up when using beanie.get()
or find_one
. I don't fully understand why, but after manually deleting the motor
users everything works.
Hope this helps someone.
Hey! Thank you for the issue. I'll check why ids are different. It is at least interesting. Or even a bug. Could you pls tell which MongoDB version you use?
Hey, It was really interesting, minus the several hours of headache 😅 . I am using mongodb 4.2.3
which is not very recent. The guide I used originally to set up pydantic + mongo
was from here . I suspect the issue may be with the PyObjectId
class used somehow creating a different ID type, but I have no way to prove it since their string versions looked identical.
Describe the bug I have a small web server that I am testing with a local
mongodb
instance. The app isFastAPI
withbeanie
for the db operations. I've noticed that when I useid
as a route parameter, callingdocument.get()
returnsNone
. However when I do afind().to_list()
the results clearly show that theid
is in fact in the DB.To Reproduce
Expected behavior What I expect to happen is that
user = await User.get(document_id = id)
returns the user object.Additional context
This is the server output when using thunder client to hit the delete endpoint. As you can see the find_all returns a User that has
6321a13c270f743661ce9633
as an id. But when I callget()
nothing is found.Request example I used:
http://127.0.0.1:8000/users/6321a13c270f743661ce9633