Skip to content

Commit 63b08a5

Browse files
committed
Merge branch 'master' into 168_169-connection_delete_entities
2 parents 8ebace3 + 83e8262 commit 63b08a5

4 files changed

Lines changed: 18 additions & 4 deletions

File tree

gcloud/datastore/connection.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,11 @@ def commit(self, dataset_id, mutation_pb):
338338
def save_entity(self, dataset_id, key_pb, properties):
339339
"""Save an entity to the Cloud Datastore with the provided properties.
340340
341+
.. note::
342+
Any existing properties for the entity identified by 'key_pb'
343+
will be replaced by those passed in 'properties'; properties
344+
not passed in 'properties' no longer be set for the entity.
345+
341346
:type dataset_id: string
342347
:param dataset_id: The dataset in which to save the entity.
343348

gcloud/datastore/entity.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def from_protobuf(cls, pb, dataset=None): # pylint: disable=invalid-name
168168

169169
@property
170170
def _must_key(self):
171-
"""Return our key.
171+
"""Return our key, or raise NoKey if not set.
172172
173173
:rtype: :class:`gcloud.datastore.key.Key`.
174174
:returns: our key
@@ -200,6 +200,12 @@ def reload(self):
200200
def save(self):
201201
"""Save the entity in the Cloud Datastore.
202202
203+
.. note::
204+
Any existing properties for the entity will be replaced by those
205+
currently set on this instance. Already-stored properties which do
206+
not correspond to keys set on this instance will be removed from
207+
the datastore.
208+
203209
:rtype: :class:`gcloud.datastore.entity.Entity`
204210
:returns: The entity with a possibly updated Key.
205211
"""

gcloud/datastore/query.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""Create / interact with gcloud datastore queries."""
22

33
import base64
4-
import copy
54

65
from gcloud.datastore import datastore_v1_pb2 as datastore_pb
76
from gcloud.datastore import _helpers
@@ -67,8 +66,9 @@ def _clone(self):
6766
:rtype: :class:`gcloud.datastore.query.Query`
6867
:returns: a copy of 'self'.
6968
"""
70-
clone = copy.deepcopy(self)
71-
clone._dataset = self._dataset # Shallow copy the dataset.
69+
clone = self.__class__(dataset=self._dataset)
70+
clone._pb.CopyFrom(self._pb)
71+
clone._cursor = self._cursor
7272
return clone
7373

7474
def to_protobuf(self):

gcloud/datastore/test_query.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,17 @@ def test__clone(self):
3333

3434
_DATASET = 'DATASET'
3535
_KIND = 'KIND'
36+
_CURSOR = 'DEADBEEF'
3637
dataset = Dataset(_DATASET)
3738
query = self._makeOne(_KIND, dataset)
39+
query._cursor = _CURSOR
3840
clone = query._clone()
3941
self.assertFalse(clone is query)
4042
self.assertTrue(isinstance(clone, self._getTargetClass()))
4143
self.assertTrue(clone.dataset() is dataset)
4244
kq_pb, = list(clone.kind())
4345
self.assertEqual(kq_pb.name, _KIND)
46+
self.assertEqual(clone._cursor, _CURSOR)
4447

4548
def test_to_protobuf_empty(self):
4649
query = self._makeOne()

0 commit comments

Comments
 (0)