Open KaerbEmEvig opened 1 month ago
Upon further investigation, the discrepancy in behaviour stems from the following change in implementation:
https://github.com/MongoEngine/mongoengine/blob/v0.10.5/mongoengine/base/document.py#L40
if self._dynamic:
dynamic_data = {}
for key, value in values.iteritems():
if key in self._fields or key == '_id':
setattr(self, key, value) # The value assignment takes place here.
elif self._dynamic:
dynamic_data[key] = value
https://github.com/MongoEngine/mongoengine/blob/v0.24.2/mongoengine/base/document.py#L65
# Set actual values
dynamic_data = {}
FileField = _import_class("FileField")
for key, value in values.items():
field = self._fields.get(key)
if field or key in ("id", "pk", "_cls"):
if __auto_convert and value is not None:
if field and not isinstance(field, FileField):
value = field.to_python(value) # The value assignment takes place here.
setattr(self, key, value)
else:
if self._dynamic:
dynamic_data[key] = value
else:
# For strict Document
self._data[key] = value
Is the conversion using to_python()
intended? Setting the __auto_convert
to False
alleviates the issue but does not look to be a feasible solution.
Downgrading (still upgrading but not as high) to mongoengine==0.20.0
makes the issue disappear.
Is this an issue with the fact that FirstDoc
is a DynamicDocument
instead of being a DynamicEmbeddedDocument
?
Trying to upgrade from
mongoengine==0.10.5
tomongoengine==0.24.2
. I get the following issue in one of the tests.Traceback:
MRE:
In
mongoengine==0.24.2
:In
mongoengine==0.10.5
:As visible above,
0.10.5
embeds theDBRef
inside aSON
object, while0.24.2
stores theDBRef
bare.RCA:
https://github.com/MongoEngine/mongoengine/blob/v0.24.2/mongoengine/dereference.py In
0.24.2
DeReference._find_references()
, we enter and add items at line 151 instead of 153, using the collection name instead of the document class as the key in our reference map.This means that
ref_document_cls_exists
isFalse
in_fetch_objects()
, hence we try to get the references withreferences = get_db()[collection].find({"_id": {"$in": refs}})
, which results in the aforementioned error.https://github.com/MongoEngine/mongoengine/blob/v0.10.5/mongoengine/dereference.py In
0.10.5
DeReference._find_references()
, we enter at line 116 instead of 114, using the document class as the key.This means that
hasattr(collection, 'objects')
isTrue
in_fetch_objects()
, hence we get the references withreferences = collection.objects.in_bulk(refs)
, which has access to the"db_alias"
inside themeta
attribute of the document class.Question
Is this an issue with my document classes or an actual bug in
mongoengine
?