Skip to content
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] UUIDs are not supported as ID types in Document.inspect_collection #838

Open
ldorigo opened this issue Jan 23, 2024 · 2 comments · May be fixed by #953
Open

[BUG] UUIDs are not supported as ID types in Document.inspect_collection #838

ldorigo opened this issue Jan 23, 2024 · 2 comments · May be fixed by #953
Labels
bug Something isn't working

Comments

@ldorigo
Copy link

ldorigo commented Jan 23, 2024

Describe the bug
MongoDB natively supports UUIDs as object IDs (see https://stackoverflow.com/questions/28895067/using-uuids-instead-of-objectids-in-mongodb). However when using Document.inspect_collection with ids that are UUIDs, it gives an error:

 TypeError: id must be an instance of (bytes, str, ObjectId), not <class 'uuid.UUID'>

To Reproduce

from beanie import Document
from pydantic import UUID4

class MyCol(Document):
  _id: UUID4
@ldorigo
Copy link
Author

ldorigo commented Jan 24, 2024

Fix is very simple - just add a union type in InspectionError in odm/models.py

class InspectionError(BaseModel):
    """
    Inspection error details
    """

    document_id: PydanticObjectId | UUID4
    error: str

@roman-right roman-right added the bug Something isn't working label Feb 8, 2024
@roman-right
Copy link
Member

Thank you for the catch.

@nikstuckenbrock nikstuckenbrock linked a pull request Jun 20, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants