Open webus opened 9 years ago
Hi @webus Thanks for reporting. It's not surprising me as we had many problems with ListDict. With which version did it happened? Have you tried with the latest master, we had several fixes in the area. If still happening, feel very welcome to submit a PR
For future reference: bug is still present in 0.16.0
For future ref, here is a minimal reproducible snippet
class TestData(DynamicDocument):
pass
TestData.drop_collection()
td = TestData(mydata=[{'name':'bob','sdata':[]}]).save()
print(TestData.objects.as_pymongo())
nested_list = td.mydata[0]['sdata']
nested_list.append({'office':'current'}) # Issue actually occurs here
print(td.mydata)
print(td._delta()) # Issue is visible here
td.save()
raw_td = list(TestData.objects.as_pymongo())[0]
print(raw_td)
assert list(raw_td.keys()) == ['_id', 'mydata'] # fails
assert raw_td["mydata"] == [{'name': 'bob', 'sdata': [{'office': 'current'}]}] # fails
Issue occurs when appending to the BaseList, MongoEngine should be marking mydata.sdata
as changed, but it marks just sdata
and so ends up adding sdata to the root of the object. Problem exist for listfield embedded in other dictfield/listfield at first sight
I try to repeat this:
At this example we created new dynamic document. Next we want to get this document and append some data to 'sdata' key in dictionary.
Let's get this document again and check our changes
As you can see mongoengine not saved new values in 'sdata' key
I found a solution how to get around this problem
But this is not the right way.