From ef1ed6a37cf9c7bec1058b7e4013697865da4a2d Mon Sep 17 00:00:00 2001 From: Juan Pineda Date: Mon, 6 May 2013 22:29:10 -0700 Subject: [PATCH 1/2] Allow __deepcopy to work with lists. --- pymongo/cursor.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pymongo/cursor.py b/pymongo/cursor.py index 4d11fe0aa8..0259c809f3 100644 --- a/pymongo/cursor.py +++ b/pymongo/cursor.py @@ -853,9 +853,12 @@ def __deepcopy(self, x, memo=None): if val_id in memo: return memo.get(val_id) memo[val_id] = y - for key, value in x.iteritems(): + # Fixed to allow deep copy of lists to solve "cannot deepcopy this pattern object". -Juan + for key, value in x.iteritems() if isinstance(x, dict) else dict(zip(range(len(x)),x)).iteritems(): if isinstance(value, dict) and not isinstance(value, SON): value = self.__deepcopy(value, memo) + elif isinstance(value, list) and not isinstance(value, SON): + value = self.__deepcopy(value, memo) elif not isinstance(value, RE_TYPE): value = copy.deepcopy(value, memo) y[copy.deepcopy(key, memo)] = value From d2970b789456bed92548174c06cc4681b87e2973 Mon Sep 17 00:00:00 2001 From: Juan Pineda Date: Tue, 7 May 2013 17:28:31 -0700 Subject: [PATCH 2/2] List copy case creates list not dict. --- pymongo/cursor.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pymongo/cursor.py b/pymongo/cursor.py index 0259c809f3..de0cefe8ae 100644 --- a/pymongo/cursor.py +++ b/pymongo/cursor.py @@ -861,5 +861,10 @@ def __deepcopy(self, x, memo=None): value = self.__deepcopy(value, memo) elif not isinstance(value, RE_TYPE): value = copy.deepcopy(value, memo) - y[copy.deepcopy(key, memo)] = value + if isinstance(x, dict) : + y[copy.deepcopy(key, memo)] = value + else : # list case + if key == 0 : + y = [] + y += value return y