Skip to content

CachedReferenceField creates DBRefs on to_python, but can't save them on to_mongo #1047

@amitlicht

Description

@amitlicht
import mongoengine
from mongoengine import Document
from mongoengine.fields import CachedReferenceField, BooleanField, IntField

mongoengine.connect('test')

class TestCachedDoc(Document):
    test = BooleanField(required=True)

class TestDoc(Document):
    cached_doc = CachedReferenceField(TestCachedDoc)
    other_field = IntField(required=True)

TestDoc.objects.delete()
TestDoc(cached_doc=TestCachedDoc(test=False).save(),
        other_field=10).save()
t = TestDoc.objects.get()
t.other_field = 1
t.save()   # --> raises mongoengine.errors.ValidationError: ValidationError (TestDoc:559003e21bacb5bcf87a3195) (A CachedReferenceField only accepts documents: ['cached_doc'])

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions