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

Datastore: empty lists are not reflected in 'client.put' #6284

Closed
crwilcox opened this issue Oct 22, 2018 · 3 comments
Closed

Datastore: empty lists are not reflected in 'client.put' #6284

crwilcox opened this issue Oct 22, 2018 · 3 comments
Assignees
Labels
api: datastore Issues related to the Datastore API. status: awaiting information type: question Request for information or clarification. Not an issue.

Comments

@crwilcox
Copy link
Contributor

crwilcox commented Oct 22, 2018

Related to #3767

Currently, Sending an empty array results in the field not being set.

from google.cloud import datastore

ds = datastore.Client()

key = ds.key('Test')
entity = datastore.Entity(key=key)
entity['children'] = []
ds.put(entity)
print(entity)
value = ds.get(entity.key)
print(value)

key = ds.key('Test')
entity = datastore.Entity(key=key)
entity['children'] = ['A']
ds.put(entity)
print(entity)
value = ds.get(entity.key)
print(value)

Output:

<Entity('Test', 5707090131681280) {'children': []}>
<Entity('Test', 5707090131681280) {}>
<Entity('Test', 5682274280407040) {'children': ['A']}>
<Entity('Test', 5682274280407040) {'children': ['A']}>
@crwilcox crwilcox added the api: datastore Issues related to the Datastore API. label Oct 22, 2018
@crwilcox crwilcox self-assigned this Oct 22, 2018
crwilcox added a commit to crwilcox/google-cloud-python that referenced this issue Oct 22, 2018
@tseaver tseaver added the type: question Request for information or clarification. Not an issue. label Oct 22, 2018
@tseaver tseaver changed the title Empty Arrays are not reflected in ds.put Datastore: empty Arrays are not reflected in ds.put Oct 22, 2018
@tseaver tseaver changed the title Datastore: empty Arrays are not reflected in ds.put Datastore: empty lists are not reflected in 'client.put' Oct 22, 2018
@tseaver
Copy link
Contributor

tseaver commented Oct 22, 2018

@dhermes You added the explicit check to exclude empty lists in 5873266. Do you recall the rationale?

@dhermes
Copy link
Contributor

dhermes commented Oct 24, 2018

@tseaver That's not where the logic was added, it just moved. ISTM that de03993 is the correct place

$ export PHRASE='if value_is_list and len(value) == 0:'
$ git grep -l "${PHRASE}"
datastore/google/cloud/datastore/helpers.py
$ git blame datastore/google/cloud/datastore/helpers.py | grep "${PHRASE}"
58732669802 gcloud/datastore/helpers.py                 (Danny Hermes    2015-12-18 17:03:35 -0800 215)         if value_is_list and len(value) == 0:
$ git log -1 58732669802 --pretty=%P  # Find parent commit
4861e7e37d8f3d7f23c06eac9c13e7298526cd21
$ git checkout 4861e7e37d8f3d7f23c06eac9c13e7298526cd21
$ git grep -l "${PHRASE}"
$ git blame gcloud/datastore/batch.py | grep "${PHRASE}"
de03993053e (Tres Seaver  2015-01-14 20:31:49 -0500 239)         if value_is_list and len(value) == 0:
$ unset PHRASE

As for this issue, does #6285 actually fix it? That is, does the backend distinguish between empty and unset?

@crwilcox
Copy link
Contributor Author

The backend very much does. If unset comes on the first one the column isn't even there. We don't send it. (which is the reason for removing the check so it would add the empty instance) It is also graphically different in the portal. not set is '-' where empty array is '[]'

crwilcox added a commit that referenced this issue Oct 26, 2018
* Fix #6284 by handling empty arrays in entity to pb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: datastore Issues related to the Datastore API. status: awaiting information type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

3 participants