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

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Minor - P4
    • Resolution: Fixed
    • None
    • 1.10.1
    • None
    • None
    • Nothing special

    Description

      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().

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: