-
Notifications
You must be signed in to change notification settings - Fork 258
Open
Description
Seems like defining id
on the beanie.Document
base class is a miss-design, as it's very frequent that your domain model has an id
field (business related, a very common field name) distinct from the underlying Mongo _id
field.
For example:
import pydantic
import beanie
# Pure pydantic model, e.g. maybe generated from OpenAPI specs, used everywhere:
class User(pydantic.BaseModel):
id : str
name : str
# ...
# Now we want to store it as such on Mongo
class UserDB(beanie.Document, User)
class Settings:
collection_name = "users"
Pylance detects the bad override Base classes for class "UserDB" define variable "id" in incompatible way
This also happens when you must create Beanie models from existing Mongo collections that use a business related id
field. In that case you cannot use Beanie.
As Pydantic doesn't support fields starting with _
, maybe _id
can be aliased to something more specific and less prone to collision, like mongoDocumentId
and still be mapped to the underlying _id
.