Skip to content

Commit

Permalink
Raise ValueError if single entity is passed to 'datastore.put'.
Browse files Browse the repository at this point in the history
Fixes #649.
  • Loading branch information
tseaver committed Feb 24, 2015
1 parent 56f60bb commit 2fa5900
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions gcloud/datastore/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

from gcloud.datastore import _implicit_environ
from gcloud.datastore.batch import Batch
from gcloud.datastore.entity import Entity
from gcloud.datastore.transaction import Transaction
from gcloud.datastore import helpers

Expand Down Expand Up @@ -252,6 +253,9 @@ def put(entities, connection=None, dataset_id=None):
one or more entities has a key with a dataset ID not matching
the passed / inferred dataset ID.
"""
if isinstance(entities, Entity):
raise ValueError("Pass a sequence of entities")

if not entities:
return

Expand Down
5 changes: 5 additions & 0 deletions gcloud/datastore/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,11 @@ def test_no_entities(self):
result = self._callFUT([])
self.assertEqual(result, None)

def test_w_single_empty_entity(self):
# https://github.com/GoogleCloudPlatform/gcloud-python/issues/649
from gcloud.datastore.entity import Entity
self.assertRaises(ValueError, self._callFUT, Entity())

def test_no_batch_w_partial_key(self):
from gcloud.datastore.test_batch import _Connection
from gcloud.datastore.test_batch import _Entity
Expand Down

0 comments on commit 2fa5900

Please sign in to comment.