MongoEngine / marshmallow-mongoengine

Mongoengine integration with marshmallow
MIT License
78 stars 34 forks source link

Fixed issue with UUID pk in ReferenceField #8

Closed AngryUbuntuNerd closed 3 years ago

AngryUbuntuNerd commented 5 years ago

When serializing a ReferenceField that uses a UUID as primary key, the serializer wont convert the UUID to a string. The created dictionary is therefore not JSON serializable and throws an exception "TypeError: Object of type UUID is not JSON serializable".

Code to reproduce this:

import json
from uuid import uuid4

from marshmallow_mongoengine import ModelSchema
from mongoengine import *

class User(Document):
    id = UUIDField(primary_key=True, default=uuid4)
    parent = ReferenceField('User')

class UserSchema(ModelSchema):
    class Meta:
        model = User

parent = User()
user = User(parent=parent)

data = UserSchema().dump(user).data
print(json.dumps(data))
AngryUbuntuNerd commented 5 years ago

it seems to be the case that CI checks are broken currently? the PR change can not possibly have caused this