mongoengine icon indicating copy to clipboard operation
mongoengine copied to clipboard

Fix dynamic embedded document updates

Open mcsimps2 opened this issue 8 months ago • 0 comments

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

mcsimps2 avatar Apr 10 '25 20:04 mcsimps2