hmarr/mongoengine — pull request #354 by aparrish (2011-11-10 20:07:39+00:00)
Title: QuerySet._transform_update incorrectly writes queries when replacing EmbeddedDocuments in lists

`append_field` wasn't getting reset to True in the loop, so fields wouldn't get appended to clean_fields after str was encountered. Example code:

```python

from mongoengine import *

class Dude(EmbeddedDocument):
name = StringField()

class Foo(EmbeddedDocument):
name = StringField()
dude = EmbeddedDocumentField(Dude)

class Baz(Document):
foos = ListField(EmbeddedDocumentField(Foo))

if __name__ == '__main__':
connect('testy')

baz = Baz(foos=[Foo(name="hi", dude=Dude(name="dungarees"))])
baz.save()

print Baz.objects(__raw__={'foos.name': 'hi'}).update_one(set__foos__S__dude=Dude(name="hat"))
```

Here's what the results look like in mongo without the fix:

```json
{
"_cls": "Baz",
"_id": ObjectId("4ebc25e7cc13b36de8000000"),
"_types": [
"Baz"
],
"foos": [
{
"_cls": "Foo",
"_types": [
"Foo"
],
"dude": [
"name"
],
"name": "hi"
}
]
}
```

Obviously borked---the embedded document in the update got mangled into a list. With the fix:

```json
{
"_cls": "Baz",
"_id": ObjectId("4ebc2da5cc13b37183000000"),
"_types": [
"Baz"
],
"foos": [
{
"_cls": "Foo",
"_types": [
"Foo"
],
"dude": {
"_types": [
"Dude"
],
"name": "hat",
"_cls": "Dude"
},
"name": "hi"
}
]
}
```

Right as rain.