Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-328

Support as_class in find_and_modify (was: as_class tries/fails to work with find_and_modify)

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.2
    • Affects Version/s: 2.1.1
    • Component/s: None
    • Labels:
    • Environment:
      debian 6, python 2.7.1. Production environ is nginx > uwsgi but the tests that demonstrate the error occur in an interactive shell

      something lik Server.db.Users = Pymongo.Connection(****).dbName.colName

      This is fine:
      >>> a = Server.db.Users.find_one({}, as_class=KeepDict)
      >>>

      This is not fine:
      >>> b = Server.db.Users.find_and_modify(query={},update={'$set':{'bogus':True}},as_class=KeepDict)
      /usr/local/lib/python2.7/dist-packages/pymongo-2.1.1-py2.7-linux-x86_64.egg/pymongo/cursor.py:666: RuntimeWarning: couldn't encode - reloading python modules and trying again. if you see this without getting an InvalidDocument exception please see http://api.mongodb.org/python/current/faq.html#does-pymongo-work-with-mod-wsgi
      Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "build/bdist.linux-x86_64/egg/pymongo/collection.py", line 1202, in find_and_modify
      File "build/bdist.linux-x86_64/egg/pymongo/database.py", line 348, in command
      File "build/bdist.linux-x86_64/egg/pymongo/collection.py", line 520, in find_one
      File "build/bdist.linux-x86_64/egg/pymongo/cursor.py", line 703, in next
      File "build/bdist.linux-x86_64/egg/pymongo/cursor.py", line 666, in _refresh
      bson.errors.InvalidDocument: Cannot encode object: <class 'keep.Types.KeepDict'>
      >>>

      Weirdly, this is also not ok:
      >>> b = Server.db.Users.find_and_modify(query={},update={'$set':{'bogus':True}},as_class=dict)
      Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "build/bdist.linux-x86_64/egg/pymongo/collection.py", line 1202, in find_and_modify
      File "build/bdist.linux-x86_64/egg/pymongo/database.py", line 348, in command
      File "build/bdist.linux-x86_64/egg/pymongo/collection.py", line 520, in find_one
      File "build/bdist.linux-x86_64/egg/pymongo/cursor.py", line 703, in next
      File "build/bdist.linux-x86_64/egg/pymongo/cursor.py", line 666, in _refresh
      bson.errors.InvalidDocument: Cannot encode object: <type 'dict'>
      >>>

            Assignee:
            ross@mongodb.com Ross Lawley
            Reporter:
            khabok Jason Voorhees
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: