Skip to content

Commit

Permalink
Merge branch 'master' into 168_169-connection_delete_entities
Browse files Browse the repository at this point in the history
  • Loading branch information
tseaver committed Oct 17, 2014
2 parents 8ebace3 + 83e8262 commit 63b08a5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
5 changes: 5 additions & 0 deletions gcloud/datastore/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,11 @@ def commit(self, dataset_id, mutation_pb):
def save_entity(self, dataset_id, key_pb, properties):
"""Save an entity to the Cloud Datastore with the provided properties.
.. note::
Any existing properties for the entity identified by 'key_pb'
will be replaced by those passed in 'properties'; properties
not passed in 'properties' no longer be set for the entity.
:type dataset_id: string
:param dataset_id: The dataset in which to save the entity.
Expand Down
8 changes: 7 additions & 1 deletion gcloud/datastore/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def from_protobuf(cls, pb, dataset=None): # pylint: disable=invalid-name

@property
def _must_key(self):
"""Return our key.
"""Return our key, or raise NoKey if not set.
:rtype: :class:`gcloud.datastore.key.Key`.
:returns: our key
Expand Down Expand Up @@ -200,6 +200,12 @@ def reload(self):
def save(self):
"""Save the entity in the Cloud Datastore.
.. note::
Any existing properties for the entity will be replaced by those
currently set on this instance. Already-stored properties which do
not correspond to keys set on this instance will be removed from
the datastore.
:rtype: :class:`gcloud.datastore.entity.Entity`
:returns: The entity with a possibly updated Key.
"""
Expand Down
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)
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

0 comments on commit 63b08a5

Please sign in to comment.