Title: There is no Query.ancestor accessor. · Issue #431 · googleapis/google-cloud-python · GitHub
Open Graph Title: There is no Query.ancestor accessor. · Issue #431 · googleapis/google-cloud-python
X Title: There is no Query.ancestor accessor. · Issue #431 · googleapis/google-cloud-python
Description: For example if a query is passes q.ancestor(None) the returned object is a clone with the ancestor removed (i.e. literally set the ancestor to None). This behavior is not mentioned in the docstring and should be added. In order to actual...
Open Graph Description: For example if a query is passes q.ancestor(None) the returned object is a clone with the ancestor removed (i.e. literally set the ancestor to None). This behavior is not mentioned in the docstring...
X Description: For example if a query is passes q.ancestor(None) the returned object is a clone with the ancestor removed (i.e. literally set the ancestor to None). This behavior is not mentioned in the docstring...
Opengraph URL: https://github.com/googleapis/google-cloud-python/issues/431
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"There is no Query.ancestor accessor.","articleBody":"For example if a query is passes `q.ancestor(None)` the [returned](https://github.com/GoogleCloudPlatform/gcloud-python/blob/c2ba130223d23c661e0844145a90c8f451de297d/gcloud/datastore/query.py#L208) object is a clone with the ancestor removed (i.e. literally set the ancestor to `None`). This behavior is not mentioned in the docstring and should be added.\n\nIn order to actually access the `ancestor`, a user needs to parse it from the query's protobuf:\n\n``` python\n\u003e\u003e\u003e from gcloud import datastore\n\u003e\u003e\u003e from gcloud.datastore import datastore_v1_pb2 as datastore_pb\n\u003e\u003e\u003e ANCESTOR = {'kind': 'Book', 'name': 'GoT'}\n\u003e\u003e\u003e ANCESTOR_KEY = datastore.key.Key(path=[ANCESTOR])\n\u003e\u003e\u003e dataset = datastore.dataset.Dataset('foo')\n\u003e\u003e\u003e q = dataset.query('Character').ancestor(ANCESTOR_KEY)\n\u003e\u003e\u003e ancestor_filters = {\n... i: filter_obj\n... for i, filter_obj in enumerate(q._pb.filter.composite_filter.filter)\n... if (filter_obj.property_filter.operator ==\n... datastore_pb.PropertyFilter.HAS_ANCESTOR)\n... }\n\u003e\u003e\u003e # for key in ancestor_filters.keys():\n... # del q._pb.filter.composite_filter.filter[key]\n... # # If q has no more filters...\n... # if not q._pb.filter.composite_filter.filter:\n... # q._pb.ClearField('filter')\n... _, filter_obj = ancestor_filters.popitem()\n\u003e\u003e\u003e ancestor_filter = filter_obj.property_filter\n\u003e\u003e\u003e ancestor_filter.property.name\nu'__key__'\n\u003e\u003e\u003e ancestor_filter.operator == datastore_pb.PropertyFilter.HAS_ANCESTOR\nTrue\n\u003e\u003e\u003e key_pb = ancestor_filter.value.key_value\n\u003e\u003e\u003e key_pb\n\u003cgcloud.datastore.datastore_v1_pb2.Key object at 0x7f069f2372a8\u003e\n\u003e\u003e\u003e key = datastore.helpers.key_from_protobuf(key_pb)\n\u003e\u003e\u003e key\n\u003cKey[{'kind': u'Book', 'name': u'GoT'}]\u003e\n\u003e\u003e\u003e ANCESTOR_KEY\n\u003cKey[{'kind': 'Book', 'name': 'GoT'}]\u003e\n```\n","author":{"url":"https://github.com/dhermes","@type":"Person","name":"dhermes"},"datePublished":"2014-12-17T23:17:36.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/431/google-cloud-python/issues/431"}
| 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:8e578047-fc0d-2a58-ac07-9a9db0a8e5ec |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B634:27F80E:114F58D:174B3CA:6A4D8D7B |
| html-safe-nonce | d990418caaff37cae63b92820faab1ba49c1a45b43f9009e4fcb467ce011caac |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNjM0OjI3RjgwRToxMTRGNThEOjE3NEIzQ0E6NkE0RDhEN0IiLCJ2aXNpdG9yX2lkIjoiNTM4NjU2ODYwOTQxMjUxNzI0MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 04d85eec792cd4caec1c5dd90cd3b60cebf3430e40b564d98932e5f978962cb0 |
| hovercard-subject-tag | issue:52305579 |
| 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/431/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e814f841d331a84f80bc1982b4c9e94579d7d663f293b596450c76449a0ef1b2/googleapis/google-cloud-python/issues/431 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e814f841d331a84f80bc1982b4c9e94579d7d663f293b596450c76449a0ef1b2/googleapis/google-cloud-python/issues/431 |
| og:image:alt | For example if a query is passes q.ancestor(None) the returned object is a clone with the ancestor removed (i.e. literally set the ancestor to None). This behavior is not mentioned in the docstring... |
| 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 | 9f8758a3953dfe943439713a6fa4f90d542a3431f10e861ca03dd7f39009f320 |
| 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 | bffd5484f01713a661b03469b77678f72b6574ed |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width