From 449b15d4ad0f678fbc46a1168fd57f2cffcd4d6a Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Fri, 17 Oct 2014 10:47:11 -0400 Subject: [PATCH 1/3] Add assertion that query cursor is copied during '_clone'. --- gcloud/datastore/test_query.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gcloud/datastore/test_query.py b/gcloud/datastore/test_query.py index 219b63c1e28c..6d0e42aab236 100644 --- a/gcloud/datastore/test_query.py +++ b/gcloud/datastore/test_query.py @@ -33,14 +33,17 @@ def test__clone(self): _DATASET = 'DATASET' _KIND = 'KIND' + _CURSOR = 'DEADBEEF' dataset = Dataset(_DATASET) query = self._makeOne(_KIND, dataset) + query._cursor = _CURSOR clone = query._clone() self.assertFalse(clone is query) self.assertTrue(isinstance(clone, self._getTargetClass())) self.assertTrue(clone.dataset() is dataset) kq_pb, = list(clone.kind()) self.assertEqual(kq_pb.name, _KIND) + self.assertEqual(clone._cursor, _CURSOR) def test_to_protobuf_empty(self): query = self._makeOne() From 137bfe27fb567ef513bd727a58614da8486646f2 Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Fri, 17 Oct 2014 10:48:21 -0400 Subject: [PATCH 2/3] Rework Query._clone to avoid spurious copy of dataset. Fixes #171. --- gcloud/datastore/query.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gcloud/datastore/query.py b/gcloud/datastore/query.py index 46b2dedb780f..8439d0b45869 100644 --- a/gcloud/datastore/query.py +++ b/gcloud/datastore/query.py @@ -67,8 +67,9 @@ def _clone(self): :rtype: :class:`gcloud.datastore.query.Query` :returns: a copy of 'self'. """ - clone = copy.deepcopy(self) - clone._dataset = self._dataset # Shallow copy the dataset. + clone = self.__class__(dataset=self._dataset) + clone._pb.CopyFrom(self._pb) + clone._cursor = self._cursor return clone def to_protobuf(self): From 7eae97f5f6e6556f69d8d74e8310bfd2df3e0ed5 Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Fri, 17 Oct 2014 13:06:43 -0400 Subject: [PATCH 3/3] Unused import. Incorporate feedback from @dhermes. --- gcloud/datastore/query.py | 1 - 1 file changed, 1 deletion(-) diff --git a/gcloud/datastore/query.py b/gcloud/datastore/query.py index 8439d0b45869..bc829ccfa69f 100644 --- a/gcloud/datastore/query.py +++ b/gcloud/datastore/query.py @@ -1,7 +1,6 @@ """Create / interact with gcloud datastore queries.""" import base64 -import copy from gcloud.datastore import datastore_v1_pb2 as datastore_pb from gcloud.datastore import _helpers