jeffjenkins/MongoAlchemy — pull request #79 by mgius (2011-11-27 22:03:17+00:00)
Title: Fix and test for updating SequenceFields

Current code doesn't support "update" on SequenceField where the underlying python sequence is modified rather than replaced outright. The result of the update operation is a purge of the Sequence from the db.

I've got a couple of test cases here. I initially thought the issue was confined to SubDocument lists but determined it was not, so there are two cases, one with IntFields and the other with SubDocuments.

I'm not entirely happy with the fix I'm proposing here, which is to detect when the list fetched from the DB differs from the current list and simply replace the old list with the new one. I suppose the "perfect" solution would be to $push and $pull the added and removed elements from the list, but only when that is more efficient that simply $setting the new list. I know for our use case, we aren't really using lists of more than a few dozen elements of fairly small size, so simply blowing away the whole thing isn't a big deal.

The location in which I'm stuffing the old value is probably not the best place as well. If there's a better place to cache the old value I'd be happy to move it there.