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))
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: