hmarr/mongoengine — Issue #361: A ListField of ReferenceField elements can't be popped or deleted
Author: maxcountryman
Created: 2011-11-21 12:52:28+00:00
State: open

I'm having a bizarre issue where I have a list of references. The list is populated and later on the references may be deleted. In order to sync these changes I thought I needed to either pop that element for the ListField or delete it. If I try to pop/delete the entire list of references is cleared. If I do nothing, and delete the reference, then the list still appears to be populated, even though the references may be dead.

Is there a better approach to this issue?

Here's an example of the problem:

Thing(Document):
string = StringField()

MyDocument(Document):
things = ListField(ReferenceField(Thing))

thing1 = Thing(string='thing one')
thing1.save()
thing2 = Thing(string='thing two')
thing2.save()
my_document = MyDocument()
my_document.things += [thing1, thing2]
my_document.save()
thing1.delete(safe=True)
del my_document.things[1]
my_document.save()

This yields an empty list at my_document.things. Note: I am using the development branch in order to make use of the UUIDField.