Always store a DBRef, Document, or EmbeddedDocument in LazyReferenceField._data

This is required to handle the case of equality tests on a LazyReferenceField
with dbref=True when comparing against a field instantiated with an ObjectId.
This commit is contained in:
Eric Timmons 2019-12-15 20:15:13 -05:00
parent 68dc2925fb
commit 329f030a41

View File

@ -2504,9 +2504,7 @@ class LazyReferenceField(BaseField):
def to_python(self, value): def to_python(self, value):
"""Convert a MongoDB-compatible type to a Python type.""" """Convert a MongoDB-compatible type to a Python type."""
if not self.dbref and not isinstance( if not isinstance(value, (DBRef, Document, EmbeddedDocument)):
value, (DBRef, Document, EmbeddedDocument)
):
collection = self.document_type._get_collection_name() collection = self.document_type._get_collection_name()
value = DBRef(collection, self.document_type.id.to_python(value)) value = DBRef(collection, self.document_type.id.to_python(value))
return value return value