Repository: MongoEngine/mongoengine

Issue:
count on ListField of EmbeddedDocumentField fails
```
    class B(EmbeddedDocument):
        c = StringField()

    class A(Document):
        b = ListField(EmbeddedDocumentField(B))

    A.objects(b=[{'c': 'c'}]).count()

    class B(EmbeddedDocument):
        c = StringField()
```

```
Traceback (most recent call last):
    A.objects(b=[{'c': 'c'}]).count()
  File "/Users/db/Documents/mongoengine/mongoengine/queryset/queryset.py", line 104, in count
    return super(QuerySet, self).count(with_limit_and_skip)
  File "/Users/db/Documents/mongoengine/mongoengine/queryset/base.py", line 347, in count
    return self._cursor.count(with_limit_and_skip=with_limit_and_skip)
  File "/Users/db/Documents/mongoengine/mongoengine/queryset/base.py", line 1481, in _cursor
    self._cursor_obj = self._collection.find(self._query,
  File "/Users/db/Documents/mongoengine/mongoengine/queryset/base.py", line 1515, in _query
    self._mongo_query = self._query_obj.to_query(self._document)
  File "/Users/db/Documents/mongoengine/mongoengine/queryset/visitor.py", line 90, in to_query
    query = query.accept(QueryCompilerVisitor(document))
  File "/Users/db/Documents/mongoengine/mongoengine/queryset/visitor.py", line 155, in accept
    return visitor.visit_query(self)
  File "/Users/db/Documents/mongoengine/mongoengine/queryset/visitor.py", line 78, in visit_query
    return transform.query(self.document, **query.query)
  File "/Users/db/Documents/mongoengine/mongoengine/queryset/transform.py", line 95, in query
    value = field.prepare_query_value(op, value)
  File "/Users/db/Documents/mongoengine/mongoengine/fields.py", line 705, in prepare_query_value
    return self.field.prepare_query_value(op, value)
  File "/Users/db/Documents/mongoengine/mongoengine/fields.py", line 570, in prepare_query_value
    value = self.document_type._from_son(value)
  File "/Users/db/Documents/mongoengine/mongoengine/base/document.py", line 686, in _from_son
    class_name = son.get('_cls', cls._class_name)
AttributeError: 'list' object has no attribute 'get'
```



Discussion:

Resolving patch:
diff --git a/mongoengine/fields.py b/mongoengine/fields.py
--- a/mongoengine/fields.py
+++ b/mongoengine/fields.py
@@ -697,7 +697,7 @@ def validate(self, value):
 
     def prepare_query_value(self, op, value):
         if self.field:
-            if op in ('set', 'unset') and (
+            if op in ('set', 'unset', None) and (
                     not isinstance(value, basestring) and
                     not isinstance(value, BaseDocument) and
                     hasattr(value, '__iter__')):


Test patch:
diff --git a/tests/queryset/queryset.py b/tests/queryset/queryset.py
--- a/tests/queryset/queryset.py
+++ b/tests/queryset/queryset.py
@@ -3613,6 +3613,15 @@ class MyDoc(Document):
         self.assertEqual(MyDoc.objects.count(), 10)
         self.assertEqual(MyDoc.objects.none().count(), 0)
 
+    def test_count_list_embedded(self):
+        class B(EmbeddedDocument):
+            c = StringField()
+
+        class A(Document):
+            b = ListField(EmbeddedDocumentField(B))
+
+        self.assertEqual(A.objects(b=[{'c': 'c'}]).count(), 0)
+
     def test_call_after_limits_set(self):
         """Ensure that re-filtering after slicing works
         """
@@ -4888,5 +4897,6 @@ class Doc(Document):
 
         self.assertEqual(1, Doc.objects(item__type__="axe").count())
 
+
 if __name__ == '__main__':
     unittest.main()