mongoengine icon indicating copy to clipboard operation
mongoengine copied to clipboard

EmbeddedDocumentList in nested embededded document save() does not find the parent document

Open jvhoffbauer opened this issue 2 years ago • 0 comments

save() not working in an EmbeddedDocumentList in nested embedded document, as _instance is an EmbeddedDocument instead of Document

Reproducer:

class TestK2(EmbeddedDocument):
  values = EmbeddedDocumentListField(StringField, default=[])

class TestK1(EmbeddedDocument): 
  k2 = EmbeddedDocumentField(TestK2)

class Main(Document):
  part = EmbeddedDocumentField(TestK1)

def main(): 
  main = Part()
  main.part.k1.k2.values.save()  # AttributeError: TestK1 has no attribute 'save'

I would assume that nested EmbeddedDocuments should have _instance pointing to the Document instance and _parent pointing to the parent doc (embedded or actual document)

jvhoffbauer avatar Oct 14 '22 16:10 jvhoffbauer