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

Key id / name should fail if set to 0 / '' #443

Closed
dhermes opened this issue Dec 18, 2014 · 4 comments
Closed

Key id / name should fail if set to 0 / '' #443

dhermes opened this issue Dec 18, 2014 · 4 comments
Assignees
Labels
api: datastore Issues related to the Datastore API. 🚨 This issue needs some love. triage me I really want to be triaged.

Comments

@dhermes
Copy link
Contributor

dhermes commented Dec 18, 2014

In Key.id(), the check

    def id(self, id_to_set=None):
        ...
        if id_to_set:
            clone = self._clone()

also ignores False-y objects other than None.

This means it ignores the integer 0, which would seem to be a valid ID. However, the backend actually rejects this, so maybe this bug only requires fixing the docstring?

>>> from gcloud import datastore
>>> cnxn = datastore.get_connection()
>>> import os
>>> dataset = cnxn.dataset(os.getenv('GCLOUD_TESTS_DATASET_ID'))
>>> entity = dataset.entity('foo')
>>> entity.key()._path
[{'kind': 'foo'}]
>>> entity.key()._path[0]['id'] = 0
>>> entity
<Entity[{'kind': 'foo', 'id': 0}] {}>
>>> entity['bar'] = u'baz'
>>> entity.save()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "gcloud/datastore/entity.py", line 246, in save
    exclude_from_indexes=self.exclude_from_indexes())
  File "gcloud/datastore/connection.py", line 477, in save_entity
    result = self.commit(dataset_id, mutation)
  File "gcloud/datastore/connection.py", line 377, in commit
    datastore_pb.CommitResponse)
  File "gcloud/datastore/connection.py", line 95, in _rpc
    data=request_pb.SerializeToString())
  File "gcloud/datastore/connection.py", line 73, in _request
    raise Exception('Request failed. Error was: %s' % content)
Exception: Request failed. Error was: Key path id is invalid. Must not be zero.

/cc @pcostell

@pcostell
Copy link
Contributor

Datastore in the near future will treat {'kind': 'foo', 'id': 0} == {'kind': 'foo'} if id is 0 or name is set and it is the empty string. Note that means setting the id = 0 is actually a request to automatically allocate the id (assuming you don't put it in the update section of the mutation).

@dhermes
Copy link
Contributor Author

dhermes commented Dec 18, 2014

So my vote is to raise an exception if a user passes 0 to id() or '' to name() so they don't assume those are allowed as actual IDs/names. If they did assume that and get an auto-allocated ID, they'd think the library was lying to them, right?

@pcostell
Copy link
Contributor

Makes sense to me.

@dhermes dhermes changed the title Key.id setter Truth-y check is too broad Key id / name should fail if set to 0 / '' Dec 30, 2014
@dhermes dhermes added the api: datastore Issues related to the Datastore API. label Dec 30, 2014
@dhermes
Copy link
Contributor Author

dhermes commented Jan 14, 2015

Deferring this to #532

@dhermes dhermes closed this as completed Jan 14, 2015
@jgeewax jgeewax modified the milestone: Datastore Stable Jan 30, 2015
@yoshi-automation yoshi-automation added triage me I really want to be triaged. 🚨 This issue needs some love. labels Apr 6, 2020
parthea pushed a commit that referenced this issue Jun 4, 2023
…pprove] (#443)

Source-Link: https://togithub.com/googleapis/synthtool/commit/e3a1277ac35fc88c09db1930533e24292b132ced
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:452901c74a22f9b9a3bd02bce780b8e8805c97270d424684bff809ce5be8c2a2
parthea pushed a commit that referenced this issue Jun 4, 2023
Source-Link: https://togithub.com/googleapis/synthtool/commit/92006bb3cdc84677aa93c7f5235424ec2b157146
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:2e247c7bf5154df7f98cce087a20ca7605e236340c7d6d1a14447e5c06791bd6
parthea pushed a commit that referenced this issue Aug 15, 2023
Source-Link: googleapis/synthtool@c4dd595
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:ce3c1686bc81145c81dd269bd12c4025c6b275b22d14641358827334fddb1d72
parthea added a commit that referenced this issue Sep 22, 2023
* chore: Update gapic-generator-python to v1.8.5

PiperOrigin-RevId: 511892190

Source-Link: googleapis/googleapis@a45d9c0

Source-Link: googleapis/googleapis-gen@1907294
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMTkwNzI5NGIxZDgzNjVlYTI0ZjhjNWYyZTA1OWE2NDEyNGM0ZWQzYiJ9

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Co-authored-by: Anthonios Partheniou <[email protected]>
parthea pushed a commit that referenced this issue Sep 22, 2023
* chore(main): release 5.0.0

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
parthea pushed a commit that referenced this issue Sep 22, 2023
Source-Link: googleapis/synthtool@50db768
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:e09366bdf0fd9c8976592988390b24d53583dd9f002d476934da43725adbb978
parthea pushed a commit that referenced this issue Sep 22, 2023
…443)

Source-Link: https://togithub.com/googleapis/synthtool/commit/395d53adeeacfca00b73abf197f65f3c17c8f1e9
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:6c1cbc75c74b8bdd71dada2fa1677e9d6d78a889e9a70ee75b93d1d0543f96e1
parthea pushed a commit that referenced this issue Oct 21, 2023
)

Source-Link: https://togithub.com/googleapis/synthtool/commit/0c7b0333f44b2b7075447f43a121a12d15a7b76a
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:08e34975760f002746b1d8c86fdc90660be45945ee6d9db914d1508acdf9a547
parthea added a commit that referenced this issue Oct 21, 2023
* chore(deps): update all dependencies

* revert

Co-authored-by: Anthonios Partheniou <[email protected]>
parthea added a commit that referenced this issue Oct 21, 2023
This library contains handwritten modules.  This PR updates the metadata file to reflect that.

https://github.com/googleapis/python-automl/tree/main/google/cloud/automl_v1beta1/services/tables

Co-authored-by: Anthonios Partheniou <[email protected]>
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. 🚨 This issue needs some love. triage me I really want to be triaged.
Projects
None yet
Development

No branches or pull requests

4 participants