diff --git a/gcloud/datastore/api.py b/gcloud/datastore/api.py index d063e01a470c..246641af5a18 100644 --- a/gcloud/datastore/api.py +++ b/gcloud/datastore/api.py @@ -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 @@ -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 diff --git a/gcloud/datastore/test_api.py b/gcloud/datastore/test_api.py index c090226377ed..85cee99ee0d3 100644 --- a/gcloud/datastore/test_api.py +++ b/gcloud/datastore/test_api.py @@ -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