PYTHON-893 - Fix application of SON manipulators in CommandCursor.

This commit is contained in:
Bernie Hackett 2015-04-14 11:07:51 -07:00
parent eda1e771f6
commit eaaa54b903
2 changed files with 28 additions and 1 deletions

View File

@ -169,7 +169,7 @@ class CommandCursor(object):
"""
if len(self.__data) or self._refresh():
coll = self.__collection
return coll.database._fix_incoming(self.__data.popleft(), coll)
return coll.database._fix_outgoing(self.__data.popleft(), coll)
else:
raise StopIteration

View File

@ -759,6 +759,33 @@ class TestDatabase(unittest.TestCase):
out = db.test.find_one()
self.assertEqual('value', out.get('value'))
def test_son_manipulator_outgoing(self):
class Thing(object):
def __init__(self, value):
self.value = value
class ThingTransformer(SONManipulator):
def transform_outgoing(self, doc, collection):
# We don't want this applied to the command return
# value in pymongo.cursor.Cursor.
if 'value' in doc:
return Thing(doc['value'])
return doc
db = self.client.foo
db.add_son_manipulator(ThingTransformer())
db.test.remove()
db.test.insert({'value': 'value'})
out = db.test.find_one()
self.assertTrue(isinstance(out, Thing))
self.assertEqual('value', out.value)
if version.at_least(self.client, (2, 6)):
out = db.test.aggregate([], cursor={}).next()
self.assertTrue(isinstance(out, Thing))
self.assertEqual('value', out.value)
def test_son_manipulator_inheritance(self):
class Thing(object):
def __init__(self, value):