title: Mongoengine - using icontains with all
body: <p>I have seen <a href="https://stackoverflow.com/questions/11287001/how-to-combine-the-usage-of-operator-all-and-icontains-for-mongoengine">this question</a> but it does not answer my question, or even pose it very well.</p>
  
  <p>I think that this is best explained with an example:</p>
  
  <pre><code>class Blah(Document):
      someList = ListField(StringField())
  
  Blah.drop_collection()
  
  Blah(someList=['lop', 'glob', 'hat']).save()
  Blah(someList=['hello', 'kitty']).save()
  
  # One of these should match the first entry
  print(Blah.objects(someList__icontains__all=['Lo']).count())
  print(Blah.objects(someList__all__icontains=['Lo']).count())
  </code></pre>
  
  <p>I assumed that this would print either <code>1, 0</code> or <code>0, 1</code> (or miraculously <code>1, 1</code>) but instead it gives</p>
  
  <pre><code>0
  Traceback (most recent call last):
    File "metst.py", line 14, in &lt;module&gt;
      print(Blah.objects(someList__all__icontains=['lO']).count())
    File "/home/blah/.pythonbrew/pythons/Python-3.1.4/lib/python3.1/site-packages/mongoengine/queryset.py", line 1034, in count
      return self._cursor.count(with_limit_and_skip=True)
    File "/home/blah/.pythonbrew/pythons/Python-3.1.4/lib/python3.1/site-packages/mongoengine/queryset.py", line 608, in _cursor
      self._cursor_obj = self._collection.find(self._query,
    File "/home/blah/.pythonbrew/pythons/Python-3.1.4/lib/python3.1/site-packages/mongoengine/queryset.py", line 390, in _query
      self._mongo_query = self._query_obj.to_query(self._document)
    File "/home/blah/.pythonbrew/pythons/Python-3.1.4/lib/python3.1/site-packages/mongoengine/queryset.py", line 213, in to_query
      query = query.accept(QueryCompilerVisitor(document))
    File "/home/blah/.pythonbrew/pythons/Python-3.1.4/lib/python3.1/site-packages/mongoengine/queryset.py", line 278, in accept
      return visitor.visit_query(self)
    File "/home/blah/.pythonbrew/pythons/Python-3.1.4/lib/python3.1/site-packages/mongoengine/queryset.py", line 170, in visit_query
      return QuerySet._transform_query(self.document, **query.query)
    File "/home/blah/.pythonbrew/pythons/Python-3.1.4/lib/python3.1/site-packages/mongoengine/queryset.py", line 755, in _transform_query
      value = field.prepare_query_value(op, value)
    File "/home/blah/.pythonbrew/pythons/Python-3.1.4/lib/python3.1/site-packages/mongoengine/fields.py", line 594, in prepare_query_value
      return self.field.prepare_query_value(op, value)
    File "/home/blah/.pythonbrew/pythons/Python-3.1.4/lib/python3.1/site-packages/mongoengine/fields.py", line 95, in prepare_query_value
      value = re.escape(value)
    File "/home/blah/.pythonbrew/pythons/Python-3.1.4/lib/python3.1/re.py", line 246, in escape
      return bytes(s)
  TypeError: 'str' object cannot be interpreted as an integer
  </code></pre>
  
  <p>Neither query works!</p>
  
  <p>Does MongoEngine support some way to search using <code>icontains</code> and <code>all</code>?  Or some way to get around this?</p>
  
  <p>Note: I want to use MongoEngine, not PyMongo.</p>
  
  <p>Edit: The same issue exists with Python 2.7.3.</p>