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 — There is no Query.ancestor accessor. · Issue #431 · googleapis/google-cloud-python

There is no Query.ancestor accessor. #431

New issue
Copy link
New issue
Copy link
Closed
Closed
There is no Query.ancestor accessor.#431
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 17, 2014
Issue body actions

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 actually access the ancestor, a user needs to parse it from the query's protobuf:

>>> from gcloud import datastore
>>> from gcloud.datastore import datastore_v1_pb2 as datastore_pb
>>> ANCESTOR = {'kind': 'Book', 'name': 'GoT'}
>>> ANCESTOR_KEY = datastore.key.Key(path=[ANCESTOR])
>>> dataset = datastore.dataset.Dataset('foo')
>>> q = dataset.query('Character').ancestor(ANCESTOR_KEY)
>>> ancestor_filters = {
...     i: filter_obj
...     for i, filter_obj in enumerate(q._pb.filter.composite_filter.filter)
...     if (filter_obj.property_filter.operator ==
...         datastore_pb.PropertyFilter.HAS_ANCESTOR)
... }
>>> # for key in ancestor_filters.keys():
... #     del q._pb.filter.composite_filter.filter[key]
... # # If q has no more filters...
... # if not q._pb.filter.composite_filter.filter:
... #     q._pb.ClearField('filter')
... _, filter_obj = ancestor_filters.popitem()
>>> ancestor_filter = filter_obj.property_filter
>>> ancestor_filter.property.name
u'__key__'
>>> ancestor_filter.operator == datastore_pb.PropertyFilter.HAS_ANCESTOR
True
>>> key_pb = ancestor_filter.value.key_value
>>> key_pb
<gcloud.datastore.datastore_v1_pb2.Key object at 0x7f069f2372a8>
>>> key = datastore.helpers.key_from_protobuf(key_pb)
>>> key
<Key[{'kind': u'Book', 'name': u'GoT'}]>
>>> ANCESTOR_KEY
<Key[{'kind': 'Book', 'name': 'GoT'}]>

Activity

Next
  1. dhermes
    added
    api: datastoreIssues related to the Datastore API.
    on Dec 17, 2014
  2. dhermes commented on Jan 6, 2015

    @dhermes
    dhermes
    on Jan 6, 2015
    ContributorAuthor
    More actions

    Fixed in #487

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

    chore: remove 'pip install' statements from python_library templates …

    78ab05d

    chore: remove 'pip install' statements from python_library templates …

    15c39a1
  8. atulep
    added a commit that references this issue on Apr 18, 2023

    chore: remove 'pip install' statements from python_library templates …

    f7ae3c5
  9. parthea
    added 2 commits that reference this issue on Jun 4, 2023

    chore(main): release 2.5.0 (#431)

    dc59798

    docs: Add documentation for enums (#431)

    b266ecf
  10. parthea
    added a commit that references this issue on Aug 15, 2023

    chore(deps): update all dependencies (#431)

    e6848ee
  11. parthea
    added a commit that references this issue on Sep 20, 2023

    build: [autoapprove] bump cryptography from 41.0.2 to 41.0.3 (#431)

    d7f67d4
  12. 9 remaining items

  13. parthea
    added 7 commits that reference this issue on Nov 24, 2025

    chore(python): update .kokoro/requirements.txt (#431)

    d261bda

    fix: use faux_conn rather than engine in unit tests (#431)

    b534e4c

    chore(deps): update dependency google-cloud-datastore to v2.15.1 (#431)

    3421d37

    chore: remove pinned Sphinx version [autoapprove] (#431)

    1a5b675

    chore: migrate to main branch (#431)

    ade7bc6

    chore(python): Push cloud library docs to Cloud RAD (#431)

    ee4bbce

    chore(python): Push cloud library docs to Cloud RAD (#431)

    34edaff
  14. parthea
    added 7 commits that reference this issue on Mar 2, 2026

    chore(deps): update dependency google-cloud-pubsub to v2.6.0 (#431)

    ef5dce1

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

    ef91e27

    ci: use all workers for presubmit check (#431)

    bd3b879

    chore(deps): update dependency charset-normalizer to v3.4.0 (#431)

    d5dd77d

    refactor: add / use 'Client._get_resource' method (#431)

    8bf265a

    tests: avoid using real credentials unit tests (#432)

    594fe9e

    chore(tests): run tests on each PR (#431)

    a1c357c
  15. parthea
    added a commit that references this issue on Sep 8, 2026

    docs: migrate code from googleapis/python-bigquery (#18303)

    23f9a74
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.