@@ -60,31 +60,6 @@ def _require_connection(connection=None):
6060 return connection
6161
6262
63- def _get_dataset_id_from_keys (keys ):
64- """Determines dataset ID from a list of keys.
65-
66- :type keys: list of :class:`gcloud.datastore.key.Key`
67- :param keys: The keys from the same dataset.
68-
69- :rtype: string
70- :returns: The dataset ID of the keys.
71- :raises: :class:`ValueError` if the key dataset IDs don't agree.
72- """
73- if any (key is None for key in keys ):
74- raise ValueError ('None not allowed' )
75-
76- dataset_id = keys [0 ].dataset_id
77- # Rather than creating a list or set of all dataset IDs, we iterate
78- # and check. We could allow the backend to check this for us if IDs
79- # with no prefix worked (GoogleCloudPlatform/google-cloud-datastore#59)
80- # or if we made sure that a prefix s~ or e~ was on each key.
81- for key in keys [1 :]:
82- if key .dataset_id != dataset_id :
83- raise ValueError ('All keys in get must be from the same dataset.' )
84-
85- return dataset_id
86-
87-
8863def get (keys , missing = None , deferred = None , connection = None ):
8964 """Retrieves entities, along with their attributes.
9065
@@ -111,7 +86,7 @@ def get(keys, missing=None, deferred=None, connection=None):
11186 return []
11287
11388 connection = _require_connection (connection )
114- dataset_id = _get_dataset_id_from_keys ( keys )
89+ dataset_id , = set ([ key . dataset_id for key in keys ] )
11590
11691 transaction = Transaction .current ()
11792
@@ -157,8 +132,7 @@ def put(entities, connection=None):
157132 in_batch = current is not None
158133 if not in_batch :
159134 keys = [entity .key for entity in entities ]
160- dataset_id = _get_dataset_id_from_keys (keys )
161- current = Batch (dataset_id = dataset_id , connection = connection )
135+ current = Batch (dataset_id = keys [0 ].dataset_id , connection = connection )
162136 for entity in entities :
163137 current .put (entity )
164138 if not in_batch :
@@ -183,8 +157,7 @@ def delete(keys, connection=None):
183157 current = Batch .current ()
184158 in_batch = current is not None
185159 if not in_batch :
186- dataset_id = _get_dataset_id_from_keys (keys )
187- current = Batch (dataset_id = dataset_id , connection = connection )
160+ current = Batch (dataset_id = keys [0 ].dataset_id , connection = connection )
188161 for key in keys :
189162 current .delete (key )
190163 if not in_batch :
0 commit comments