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 — Datastore API key.Key.id() throws TypeError: 'long' object is not callable · Issue #2456 · googleapis/google-cloud-python

Datastore API key.Key.id() throws TypeError: 'long' object is not callable #2456

New issue
Copy link
New issue
Copy link
Closed
Closed
Datastore API key.Key.id() throws TypeError: 'long' object is not callable#2456
Copy link
Assignees
dhermes
Labels
api: datastoreIssues related to the Datastore API.

Description

@theoschao
theoschao
opened on Sep 28, 2016
Issue body actions

As part of a datastore query, I get back entities that have a KeyProperty. When trying to call a .id() on the KeyProperty, I get the following TypeError thrown:

TypeError: 'long' object is not callable

Upon examining the particular key, I see this (obfuscated):

<Key[{'kind': u'xxxx', 'id': 1234567890L}], project=xxxx>

Not sure exactly where the TypeError is being thrown, but it looks like the 'id' is being interpreted as a long somehow, when it's actually a standard integer.

I've had to workaround this by doing the following:
Key._path[0].get('id')

Activity

  1. dhermes
    added
    api: datastoreIssues related to the Datastore API.
    on Sep 28, 2016
  2. dhermes commented on Sep 28, 2016

    @dhermes
    dhermes
    on Sep 28, 2016
    Contributor
    More actions

    @theoschao Can you give a snippet of the code you're using to invoke the error? A Key Property may come from the low-level protobuf interface, but it's unclear if you've used that or the more user-friendly high-level interface.

  3. theoschao commented on Sep 28, 2016

    @theoschao
    theoschao
    on Sep 28, 2016
    Author
    More actions

    @dhermes sure, I've stripped the code down to what's relevant to understand:

    from google.cloud import datastore
    from oauth2client.service_account import ServiceAccountCredentials
    
    svc_account_credentials = ServiceAccountCredentials._from_p12_keyfile_contents(
      service_account_email=CLIENT_EMAIL,
      private_key_pkcs12=PRIVATEKEYSTRING,
      scopes=datastore.SCOPE
    )
    
    client = datastore.Client(credentials=svc_account_credentials, project='xxx')
    
    # Let's say Account has a KeyProperty
    query_obj = client.query(kind='Account')
    
    query_iterator = query_obj.fetch(limit=1000)
    # btw, it's unfortunate that we can only get up to 300 results per batch of results now :(
    entities, more_results, next_cursor = query_iterator.next_page()
    
    for entity in entities:
      for field in entity:
        # this is one of a few cases written to handle different data types, assume getType() gets the type of a given property
        if getType(field) == KEYPROPERTY:
          value = field.id()  # see https://googlecloudplatform.github.io/google-cloud-python/stable/datastore-keys.html#google.cloud.datastore.key.Key.id

    it's at the value = field.id() line that I see this error, and it's here where I replaced it with value = field._path[0].get('id') from looking at the source code

  4. dhermes commented on Sep 28, 2016

    @dhermes
    dhermes
    on Sep 28, 2016
    Contributor
    More actions

    What is KEYPROPERTY? ISTM that it is just a Key. If that's the case, id is a @property which means you need to call field.id not field.id(). Since a @property, field.id will return an integer, which can't be called. For example:

    >>> n = 1
    >>> n()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: 'int' object is not callable
    >>>
    >>> n = 1L
    >>> n()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: 'long' object is not callable

    Please re-open if I'm mistaken.

  5. dhermes
    closed this as completedon Sep 28, 2016
  6. theoschao commented on Sep 28, 2016

    @theoschao
    theoschao
    on Sep 28, 2016
    Author
    More actions

    @dhermes bingo! you're right. I was in the process of upgrading our gcloud library from a super old version (0.3.0) to something more recent and it looks like that @property decorator was added and I hadn't noticed. Thanks!

  7. dhermes commented on Sep 29, 2016

    @dhermes
    dhermes
    on Sep 29, 2016
    Contributor
    More actions

    Sure thing!

  8. JustinBeckwith
    assigned
    dhermes
    on Feb 1, 2021
  9. parthea
    added a commit that references this issue on Nov 24, 2025

    fix: resolve issue where rest-numeric-enums=False is not supported (#…

    004de63
  10. parthea
    added 2 commits that reference this issue on Apr 1, 2026

    docs: update multimodal dataframe notebook to use public APIs (#2456)

    c2eda3e

    chore: librarian release pull request: 20260217T233413Z (#2461)

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

Metadata

Metadata

Assignees

  • @dhermes
    dhermes

Labels

api: datastoreIssues related to the Datastore API.

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.