Skip to content

Commit 6e69f41

Browse files
committed
Don't copy key's datset ID to the protobuf.
The back-end already knows it, and it is actually different than the 'project ID' we are assigning to the dataset as its ID. Fixes #121.
1 parent 7f6e4b1 commit 6e69f41

File tree

2 files changed

+6
-15
lines changed

2 files changed

+6
-15
lines changed

gcloud/datastore/key.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,9 @@ def to_protobuf(self):
9191
"""
9292
key = datastore_pb.Key()
9393

94-
# Technically a dataset is required to do anything with the key,
95-
# but we shouldn't throw a cryptic error if one isn't provided
96-
# in the initializer.
97-
if self.dataset():
98-
# Apparently 's~' is a prefix for High-Replication and is necessary
99-
# here. Another valid preflix is 'e~' indicating EU datacenters.
100-
dataset_id = self.dataset().id()
101-
if dataset_id:
102-
if dataset_id[:2] not in ['s~', 'e~']:
103-
dataset_id = 's~' + dataset_id
104-
105-
key.partition_id.dataset_id = dataset_id
94+
# Don't copy the dataset ID to the protobuf: the backend
95+
# already knows the dataset we are working with, and sets
96+
# it on returned keys.
10697

10798
if self._namespace:
10899
key.partition_id.namespace = self._namespace

gcloud/datastore/test_key.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,23 +139,23 @@ def test_to_protobuf_w_explicit_dataset_no_prefix(self):
139139
dataset = Dataset(_DATASET)
140140
key = self._makeOne(dataset)
141141
pb = key.to_protobuf()
142-
self.assertEqual(pb.partition_id.dataset_id, 's~%s' % _DATASET)
142+
self.assertEqual(pb.partition_id.dataset_id, '')
143143

144144
def test_to_protobuf_w_explicit_dataset_w_s_prefix(self):
145145
from gcloud.datastore.dataset import Dataset
146146
_DATASET = 's~DATASET'
147147
dataset = Dataset(_DATASET)
148148
key = self._makeOne(dataset)
149149
pb = key.to_protobuf()
150-
self.assertEqual(pb.partition_id.dataset_id, _DATASET)
150+
self.assertEqual(pb.partition_id.dataset_id, '')
151151

152152
def test_to_protobuf_w_explicit_dataset_w_e_prefix(self):
153153
from gcloud.datastore.dataset import Dataset
154154
_DATASET = 'e~DATASET'
155155
dataset = Dataset(_DATASET)
156156
key = self._makeOne(dataset)
157157
pb = key.to_protobuf()
158-
self.assertEqual(pb.partition_id.dataset_id, _DATASET)
158+
self.assertEqual(pb.partition_id.dataset_id, '')
159159

160160
def test_to_protobuf_w_explicit_namespace(self):
161161
_NAMESPACE = 'NAMESPACE'

0 commit comments

Comments
 (0)