MongoEngine / MongoEngine/mongoengine
Mongoengine makes conflicting modifications to embedded documents
Open
Nobody has claimed this yet.
Bug
- Dominant language
- Python
- Stars
- 4.3k
- Forks
- 1.2k
- Avg merge
- 4h 41m
- Merged PRs (30d)
- 11
Description
Some embedded document structures trip up delta tracking and cause saves to fail. For example, take the following script:
import mongoengine
class EmbeddedDoc(mongoengine.EmbeddedDocument):
content = mongoengine.StringField()
docs = mongoengine.ListField(mongoengine.EmbeddedDocumentField('EmbeddedDoc'))
class Doc(mongoengine.Document):
docs = mongoengine.ListField(mongoengine.EmbeddedDocumentField(EmbeddedDoc))
mongoengine.connect('test')
Doc.objects.delete()
d = Doc()
d.docs = [EmbeddedDoc(content='1', docs=[])]
d.save()
d = Doc.objects[0]
e = EmbeddedDoc()
e.content = '2'
d.docs[0].docs.insert(0, e)
d.save()
The final call to save() fails with an error:
Traceback (most recent call last):
File "break-mongoengine.py", line 24, in <module>
d.save()
File "/home/sm/Code/ma/venv/src/mongoengine/mongoengine/document.py", line 372, in save
raise OperationError(message % six.text_type(err))
mongoengine.errors.OperationError: Could not save document (Cannot update 'docs.0.docs.0.content' and 'docs.0.docs' at the same time)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Run the reproduction in break-mongoengine.py and start from the save path in mongoengine/document.py, where the OperationError is raised. Trace how the nested embedded-document changes become update operations. Done means the final d.save() succeeds without MongoDB reporting conflicting updates to docs.0.docs.0.content and docs.0.docs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mongodb, python
- Domain
- database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100