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

fix empty set #404

Closed
wants to merge 4 commits into from
Closed
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
7 changes: 7 additions & 0 deletions gcloud/datastore/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,10 @@ def save_entity(self, dataset_id, key_pb, properties,
will be replaced by those passed in 'properties'; properties
not passed in 'properties' no longer be set for the entity.

.. note::
When saving an entity to the backend, properties whose value are

This comment was marked as spam.

Empty lists or none cannot be saved and will be ignore.

This comment was marked as spam.


:type dataset_id: string
:param dataset_id: The dataset in which to save the entity.

Expand Down Expand Up @@ -407,6 +411,9 @@ def save_entity(self, dataset_id, key_pb, properties,
insert.key.CopyFrom(key_pb)

for name, value in properties.items():
if isinstance(value, list) and len(value) == 0:
continue

prop = insert.property.add()
# Set the name of the property.
prop.name = name
Expand Down
3 changes: 2 additions & 1 deletion gcloud/datastore/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,8 @@ def test_save_entity_wo_transaction_w_upsert(self):
'commit',
])
http = conn._http = Http({'status': '200'}, rsp_pb.SerializeToString())
result = conn.save_entity(DATASET_ID, key_pb, {'foo': u'Foo'})
result = conn.save_entity(DATASET_ID, key_pb,
{'foo': u'Foo', 'bar': []})

This comment was marked as spam.

self.assertEqual(result, True)
cw = http._called_with
self.assertEqual(cw['uri'], URI)
Expand Down