Skip to content

no_dereference() disables dereferencing in other documents referencing document #1677

@flacerdk

Description

@flacerdk

As in this example:

import os

from mongoengine import Document, ReferenceField, connect


connect(host=os.getenv('DB'))


class A(Document):
    pass


class B(Document):
    a = ReferenceField(A)


class C(Document):
    b = ReferenceField(B)


a = A().save()
b = B(a=a).save()
c = C(b=b).save()

c = C.objects.get(id=c.id)

B.objects.no_dereference().get(id=c.b.id)
print(isinstance(c.b.a, A))  # prints False

B.objects.get(id=c.b.id)
print(isinstance(c.b.a, A))  # prints True

Is this expected behavior? Outside of the context manager, the documentation says nothing about no_dereference() affecting other querysets.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions