From eaaa54b9035c0b75520613bb3e73e1b496e7b18f Mon Sep 17 00:00:00 2001 From: Bernie Hackett Date: Tue, 14 Apr 2015 11:07:51 -0700 Subject: [PATCH] PYTHON-893 - Fix application of SON manipulators in CommandCursor. --- pymongo/command_cursor.py | 2 +- test/test_database.py | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/pymongo/command_cursor.py b/pymongo/command_cursor.py index 6b2bc5c57..d8becadec 100644 --- a/pymongo/command_cursor.py +++ b/pymongo/command_cursor.py @@ -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 diff --git a/test/test_database.py b/test/test_database.py index f866d92f2..74e70dd63 100644 --- a/test/test_database.py +++ b/test/test_database.py @@ -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):