Skip to content

Commit 49977da

Browse files
committed
Use 'helpers._dataset_ids_equal'.
1 parent a6cea31 commit 49977da

1 file changed

Lines changed: 6 additions & 18 deletions

File tree

gcloud/datastore/batch.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -193,22 +193,6 @@ def add_auto_id_entity(self, entity):
193193

194194
self._auto_id_entities.append(entity)
195195

196-
def _match_dataset_id(self, other_id):
197-
"""Ensure that `other_id` matches our `dataset_id`.
198-
199-
Helper for :meth:`put` and :meth:`delete`.
200-
201-
:type other_id: string
202-
:param other_id: the dataset ID to compare
203-
204-
:raises: ValueError if `other_id` does not match (even after stripping
205-
any prefix).
206-
"""
207-
other_id = other_id.rsplit('~', 1)[-1]
208-
our_id = self._dataset_id.rsplit('~', 1)[-1]
209-
if other_id != our_id:
210-
raise ValueError("Key must be from same dataset as batch")
211-
212196
def put(self, entity):
213197
"""Remember an entity's state to be saved during ``commit``.
214198
@@ -232,7 +216,9 @@ def put(self, entity):
232216
if entity.key is None:
233217
raise ValueError("Entity must have a key")
234218

235-
self._match_dataset_id(entity.key.dataset_id)
219+
if not helpers._dataset_ids_equal(self._dataset_id,
220+
entity.key.dataset_id):
221+
raise ValueError("Key must be from same dataset as batch")
236222

237223
_assign_entity_to_mutation(
238224
self.mutation, entity, self._auto_id_entities)
@@ -249,7 +235,9 @@ def delete(self, key):
249235
if key.is_partial:
250236
raise ValueError("Key must be complete")
251237

252-
self._match_dataset_id(key.dataset_id)
238+
if not helpers._dataset_ids_equal(self._dataset_id,
239+
key.dataset_id):
240+
raise ValueError("Key must be from same dataset as batch")
253241

254242
key_pb = key.to_protobuf()
255243
helpers._add_keys_to_request(self.mutation.delete, [key_pb])

0 commit comments

Comments
 (0)