Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#649: Raise ValueError if single entity is passed to 'datastore.put'. #677

Merged
merged 1 commit into from
Feb 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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