Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #171: rework query clone to avoid spurious copy of dataset #254

Merged
merged 3 commits into from
Oct 17, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions gcloud/datastore/query.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -67,8 +66,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)

This comment was marked as spam.

clone._cursor = self._cursor
return clone

def to_protobuf(self):
Expand Down
3 changes: 3 additions & 0 deletions gcloud/datastore/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down