Skip to content

Commit 2fa5900

Browse files
committed
Raise ValueError if single entity is passed to 'datastore.put'.
Fixes #649.
1 parent 56f60bb commit 2fa5900

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

gcloud/datastore/api.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
from gcloud.datastore import _implicit_environ
2222
from gcloud.datastore.batch import Batch
23+
from gcloud.datastore.entity import Entity
2324
from gcloud.datastore.transaction import Transaction
2425
from gcloud.datastore import helpers
2526

@@ -252,6 +253,9 @@ def put(entities, connection=None, dataset_id=None):
252253
one or more entities has a key with a dataset ID not matching
253254
the passed / inferred dataset ID.
254255
"""
256+
if isinstance(entities, Entity):
257+
raise ValueError("Pass a sequence of entities")
258+
255259
if not entities:
256260
return
257261

gcloud/datastore/test_api.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,11 @@ def test_no_entities(self):
627627
result = self._callFUT([])
628628
self.assertEqual(result, None)
629629

630+
def test_w_single_empty_entity(self):
631+
# https://github.com/GoogleCloudPlatform/gcloud-python/issues/649
632+
from gcloud.datastore.entity import Entity
633+
self.assertRaises(ValueError, self._callFUT, Entity())
634+
630635
def test_no_batch_w_partial_key(self):
631636
from gcloud.datastore.test_batch import _Connection
632637
from gcloud.datastore.test_batch import _Entity

0 commit comments

Comments
 (0)