Skip to content

Fix dynamic embedded document updates #2882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mcsimps2
Copy link
Contributor

@mcsimps2 mcsimps2 commented Apr 10, 2025

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

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. This enables operations like `A.objects(...).update(foo__newfield="bar")`.

Resolves MongoEngine#2486
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EmbeddedDocumentField errors during update when adding new field to DynamicEmbeddedDocument
1 participant