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

as_class option is not propogated by Cursor.clone. cursor = collection.find(as_class=MyClass) \ print type cursor[0] #result is dict

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 1.10.1
    • Affects Version/s: None
    • Component/s: None
    • None
    • Environment:
      Nothing special

      Here is the unit test (pseudocode).

      Class MyClass(object):
      """
      Class has _getitem_ and _setitem_ (possibly because it inherits from dict).
      """
      pass

      cursor = some_collection.find(as_class=MyClass)
      for c in cursor:
      print type (c) # result is MyClass

      cursor = some_collection.find(as_class=MyClass)
      c = cursor[0]
      print type (c) # result is dict

      I believe the problem is in Cursor.clone:

      copy = Cursor(self._collection, self.spec, self._fields,
      self._skip, self.limit, self._timeout,
      self._tailable, self.snapshot, as_class = self._as_class)

      When the copy is made (for _getitem_) the as_class property is lost.

      find_one() internally does a

      for result in self.find(spec_or_id, *args, **kwargs).limit(-1):

      so you only see the problem in find() not find_one().

            Assignee:
            bernie@mongodb.com Bernie Hackett
            Reporter:
            campanadavid David Campana
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: