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

DictField with an EmbeddedDocument value produces error #378

Open
tiltowait opened this issue Aug 12, 2022 · 0 comments
Open

DictField with an EmbeddedDocument value produces error #378

tiltowait opened this issue Aug 12, 2022 · 0 comments

Comments

@tiltowait
Copy link

I am trying to set an EmbeddedDocument as a value in a DictField, which according to #99 should work. However, when I do so, I receive the following error:

bson.errors.InvalidDocument: cannot encode object: <object EmbeddedDocument objects.items.MockItem({'uuid': UUID('cee1f505-1014-4bc8-9095-7047c869587c'), '_token_id': '1583', 'durability': 100})>, of type: <Implementation class 'objects.items.MockItem'>

The DictField's definition:

    _slots = fields.DictField(attribute="slots")

The MockItem EmbeddedDocument:

instance.register
class MockItem(EmbeddedDocument):
    """An item with associated durability."""

    uuid = fields.UUIDField(default=uuid.uuid4)
    _token_id = fields.StrField(required=True, attribute="tokenId")
    durability = fields.IntField(default=100)
    _item = None

    # Custom __getattr__ and __hash__ omitted

Stepping through the debugger, prior to attempting to commit(), the _slots dict has the following value:

<object umongo.data_objects.Dict({'base': None, 'pet': None, 'cloak': None, 'oh': None, 'body': None, 'hair': None, 'ears': None, 'face': None, 'legs': None, 'feet': None, 'chest': None, 'hands': None, 'waist': None, 'head': None, 'mh': <object EmbeddedDocument objects.items.MockItem({'uuid': UUID('d28a07c1-49b3-4099-be44-4733d04420cd'), '_token_id': '-104', 'durability': 100})>})>

In my AsyncioMotorClient, I am setting uuidRepresentation="standard", but I get the error with or without the UUID field present. What am I doing wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant