GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Key id / name should fail if set to 0 / '' · Issue #443 · googleapis/google-cloud-python

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

New issue
Copy link
New issue
Copy link
Closed
Closed
Key id / name should fail if set to 0 / ''#443
Copy link
Assignees
dhermes
Labels
🚨This issue needs some love.api: datastoreIssues related to the Datastore API.triage meI really want to be triaged.

Description

@dhermes
dhermes
opened on Dec 18, 2014
Issue body actions

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

Activity

Next
  1. pcostell commented on Dec 18, 2014

    @pcostell
    pcostell
    on Dec 18, 2014
    Contributor
    More actions

    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).

  2. dhermes commented on Dec 18, 2014

    @dhermes
    dhermes
    on Dec 18, 2014
    ContributorAuthor
    More actions

    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?

  3. pcostell commented on Dec 18, 2014

    @pcostell
    pcostell
    on Dec 18, 2014
    Contributor
    More actions

    Makes sense to me.

  4. dhermes
    changed the title [-]Key.id setter Truth-y check is too broad[/-] [+]Key id / name should fail if set to 0 / ''[/+] on Dec 30, 2014
  5. dhermes
    added
    api: datastoreIssues related to the Datastore API.
    on Dec 30, 2014
  6. dhermes commented on Jan 14, 2015

    @dhermes
    dhermes
    on Jan 14, 2015
    ContributorAuthor
    More actions

    Deferring this to #532

  7. dhermes
    closed this as completedon Jan 14, 2015
  8. jgeewax
    modified the milestone: This milestone has been deleted on Jan 30, 2015
  9. yoshi-automation
    added
    triage meI really want to be triaged.
    🚨This issue needs some love.
    on Apr 6, 2020
  10. JustinBeckwith
    assigned
    dhermes
    on Feb 1, 2021
  11. parthea
    added 2 commits that reference this issue on Jun 4, 2023

    chore(python): update dependencies in .kokoro/requirements.txt [autoa…

    8ac0aca

    chore(deps): Update nox in .kokoro/requirements.in [autoapprove] (#443)

    e6c5579
  12. parthea
    added a commit that references this issue on Aug 15, 2023

    chore(python): exclude grpcio==1.49.0rc1 in tests [autoapprove] (#443)

    2d049da
  13. 8 remaining items

  14. parthea
    added a commit that references this issue on Aug 21, 2025

    chore(python): use ubuntu 22.04 in docs image (#443)

    ed8bcb9
  15. parthea
    added 3 commits that reference this issue on Sep 16, 2025

    chore(python): use ubuntu 22.04 in docs image (#443)

    ca0ec47

    feat: accepts a table ID, which downloads the table without a query (#…

    4dc6ff7

    chore(main): release 0.17.0 (#472)

    8a5066c
  16. parthea
    added 7 commits that reference this issue on Nov 24, 2025

    fix: add field headers for other http verbs (#443)

    de415aa

    chore(python): bump idna from 3.4 to 3.7 in .kokoro (#443)

    b6f5db8

    chore(main): release 2.10.1 (#443)

    5ebb2d8

    chore(python): Enable size-label bot (#443)

    1a7a437

    build(deps): bump cryptography from 39.0.1 to 41.0.0 in /synthtool/gc…

    0686509

    build(deps): [autoapprove] bump certifi from 2022.12.7 to 2023.7.22 (#…

    c26b2df

    fix: refactor transactions to use their own event loops (#443)

    506d925
  17. parthea
    added 4 commits that reference this issue on Mar 2, 2026

    chore(deps): update dependency backoff to v1.11.0 (#443)

    d32e016

    chore: configure renovate (#443)

    8616d53

    chore(deps): update dependency jaraco-classes to v3.4.0 (#443)

    3a07b69

    refactor: add / use 'Client._post_resource' method (#443)

    bab9c65
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @dhermes
    dhermes

Labels

🚨This issue needs some love.api: datastoreIssues related to the Datastore API.triage meI really want to be triaged.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.