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

    • Type: Bug
    • Status: Closed
    • Priority: Minor - P4
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.10.1
    • Component/s: None
    • Labels:
      None
    • Environment:
      Nothing special
    • # Replies:
      1
    • Last comment by Customer:
      true

      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

            • Votes:
              1 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since reply:
                7 years, 43 weeks, 2 days ago
                Date of 1st Reply: