Skip to content

Commit

Permalink
Only using explicit namespace when deserializing key pb.
Browse files Browse the repository at this point in the history
This issue surfaced during review for googleapis#282.
  • Loading branch information
dhermes committed Oct 23, 2014
1 parent b6d3e74 commit 12695c2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 6 additions & 1 deletion gcloud/datastore/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,18 @@ def save(self):
transaction.add_auto_id_entity(self)

if isinstance(key_pb, datastore_pb.Key):
# Update the path (which may have been altered).
# NOTE: The underlying namespace can't have changed in a save().
# The value of the dataset ID may have changed from implicit
# (i.e. None, with the ID implied from the dataset.Dataset
# object associated with the Entity/Key), but if it was
# implicit before the save() we leave it as implicit.
path = []
for element in key_pb.path_element:
key_part = {}
for descriptor, value in element._fields.items():
key_part[descriptor.name] = value
path.append(key_part)
# Update the path (which may have been altered).
self._key = key.path(path)

return self
Expand Down
8 changes: 6 additions & 2 deletions gcloud/datastore/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,12 @@ def key_from_protobuf(pb):

path.append(element_dict)

dataset_id = pb.partition_id.dataset_id or None
namespace = pb.partition_id.namespace
dataset_id = None
if pb.partition_id.HasField('dataset_id'):
dataset_id = pb.partition_id.dataset_id
namespace = None
if pb.partition_id.HasField('namespace'):
namespace = pb.partition_id.namespace

return Key(path, namespace, dataset_id)

Expand Down

0 comments on commit 12695c2

Please sign in to comment.