Closed amoallim15 closed 1 year ago
The Document
class already has a built in id
field that is generated when the document is created. It's type is PydanticObjectId
, which clashes with the UUID
type that you have. I'd recommend simply getting rid of your own id
field and use the built-in.
Docs: https://roman-right.github.io/beanie/api-documentation/document/
The
Document
class already has a built inid
field that is generated when the document is created. It's type isPydanticObjectId
, which clashes with theUUID
type that you have. I'd recommend simply getting rid of your ownid
field and use the built-in. Docs: https://roman-right.github.io/beanie/api-documentation/document/
But the docs also mention you can use UUID as id type: https://beanie-odm.dev/tutorial/async/defining-a-document/#id
So maybe the id: Optional[PydanticObjectId] = None
should be typed such that it allows UUID as well
This issue is stale because it has been open 30 days with no activity.
The
Document
class already has a built inid
field that is generated when the document is created. It's type isPydanticObjectId
, which clashes with theUUID
type that you have. I'd recommend simply getting rid of your ownid
field and use the built-in. Docs: https://roman-right.github.io/beanie/api-documentation/document/But the docs also mention you can use UUID as id type: https://beanie-odm.dev/tutorial/async/defining-a-document/#id
So maybe the
id: Optional[PydanticObjectId] = None
should be typed such that it allows UUID as well
More concretely, this would mean changing
id: Optional[PydanticObjectId] = None
to
id: Union[PydanticObjectId, UUID, None] = None
(+ of course making all the other code ready for this, writing tests, making mypy happy)
Did give this a quick try the other day, it's harder than it looks; so before me (or someone else) take a stab at a PR, it would help knowing if the maintainers agree on the approach :)
This issue is stale because it has been open 30 days with no activity.
This issue was closed because it has been stalled for 14 days with no activity.
Describe the bug (error: Incompatible types in assignment (expression has type "UUID", base class "Document" defined the type as "Optional[PydanticObjectId]"))
To Reproduce
Expected behavior no errors. temporary solution:
Additional context N/A