Title: Key id / name should fail if set to 0 / '' · Issue #443 · googleapis/google-cloud-python · GitHub
Open Graph Title: Key id / name should fail if set to 0 / '' · Issue #443 · googleapis/google-cloud-python
X Title: Key id / name should fail if set to 0 / '' · Issue #443 · googleapis/google-cloud-python
Description: 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 actua...
Open Graph Description: 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 b...
X Description: 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 b...
Opengraph URL: https://github.com/googleapis/google-cloud-python/issues/443
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Key id / name should fail if set to 0 / ''","articleBody":"In [`Key.id()`](https://github.com/GoogleCloudPlatform/gcloud-python/blob/8a6feffb5381a7d738c8ecfd0e4d85efd4564dfe/gcloud/datastore/key.py#L188), the check\n\n``` python\n def id(self, id_to_set=None):\n ...\n if id_to_set:\n clone = self._clone()\n```\n\nalso ignores `False`-y objects other than `None`.\n\nThis 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?\n\n``` python\n\u003e\u003e\u003e from gcloud import datastore\n\u003e\u003e\u003e cnxn = datastore.get_connection()\n\u003e\u003e\u003e import os\n\u003e\u003e\u003e dataset = cnxn.dataset(os.getenv('GCLOUD_TESTS_DATASET_ID'))\n\u003e\u003e\u003e entity = dataset.entity('foo')\n\u003e\u003e\u003e entity.key()._path\n[{'kind': 'foo'}]\n\u003e\u003e\u003e entity.key()._path[0]['id'] = 0\n\u003e\u003e\u003e entity\n\u003cEntity[{'kind': 'foo', 'id': 0}] {}\u003e\n\u003e\u003e\u003e entity['bar'] = u'baz'\n\u003e\u003e\u003e entity.save()\nTraceback (most recent call last):\n File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\n File \"gcloud/datastore/entity.py\", line 246, in save\n exclude_from_indexes=self.exclude_from_indexes())\n File \"gcloud/datastore/connection.py\", line 477, in save_entity\n result = self.commit(dataset_id, mutation)\n File \"gcloud/datastore/connection.py\", line 377, in commit\n datastore_pb.CommitResponse)\n File \"gcloud/datastore/connection.py\", line 95, in _rpc\n data=request_pb.SerializeToString())\n File \"gcloud/datastore/connection.py\", line 73, in _request\n raise Exception('Request failed. Error was: %s' % content)\nException: Request failed. Error was: Key path id is invalid. Must not be zero.\n```\n\n/cc @pcostell \n","author":{"url":"https://github.com/dhermes","@type":"Person","name":"dhermes"},"datePublished":"2014-12-18T22:29:36.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/443/google-cloud-python/issues/443"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:af303cfa-8e56-4796-77e6-1dfb80b77446 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8E0A:135B7:17826E7:2068C30:6A4DF68D |
| html-safe-nonce | 0a4d224ca6e9eb881020a0963a63839ac3dfb9f9465573128ba1003d3ee71c04 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RTBBOjEzNUI3OjE3ODI2RTc6MjA2OEMzMDo2QTRERjY4RCIsInZpc2l0b3JfaWQiOiI2ODE3NDUyMTcyNTU0MTM5Mjc4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 280e4c4cc77436b4ed519e16c9f9944aeadffdeeeb43d71942425fc30975bf5f |
| hovercard-subject-tag | issue:52424778 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/googleapis/google-cloud-python/443/issue_layout |
| twitter:image | https://opengraph.githubassets.com/96df5cde6346d1834b4ee9fbd9ba6a7bb89ae22b60e2f3933b5dae85edde14e4/googleapis/google-cloud-python/issues/443 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/96df5cde6346d1834b4ee9fbd9ba6a7bb89ae22b60e2f3933b5dae85edde14e4/googleapis/google-cloud-python/issues/443 |
| og:image:alt | 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 b... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dhermes |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5818716c93c6a2925b815402541a32814e43a7b1261c322b0c2df75224289566 |
| turbo-cache-control | no-preview |
| go-import | github.com/googleapis/google-cloud-python git https://github.com/googleapis/google-cloud-python.git |
| octolytics-dimension-user_id | 16785467 |
| octolytics-dimension-user_login | googleapis |
| octolytics-dimension-repository_id | 16316451 |
| octolytics-dimension-repository_nwo | googleapis/google-cloud-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 16316451 |
| octolytics-dimension-repository_network_root_nwo | googleapis/google-cloud-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | f4bb89367ca678f057d79b1abc45d6675b1bd5b2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width