mongoengine
mongoengine copied to clipboard
Fix dynamic embedded document updates
In order to allow setting new fields that did not previouly exist on dynamic embedded documents, the lookup_member functions on EmbeddedDocumentField and GenericEmbeddedDocumentField return dynamic fields as appropriate. Special awareness is given to positional operators - see the new test cases for examples of where this is important.
Here's an example of what this now allows
class Wheel(DynamicEmbeddedDocument):
position = StringField()
class Car(Document):
wheels = EmbeddedDocumentListField(Wheel)
# This is now allowed - adding a new field to the dynamic embedded document
Car.objects(wheels__position="front-driver").update(
set__wheels__S__damaged=True
)
Resolves #2486