Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9142421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:46:47+00:00 2026-06-17T09:46:47+00:00

I pass an NDB Key() with a parent to a deferred function. In this

  • 0

I pass an NDB Key() with a parent to a deferred function. In this function I retrieve the entity again. But I cannot use the passed key to get the entity directly. I have to change the key order pairing in the ndb.Key().

deferred.defer(my_deferred.a_function, entity.key)  

The entity.key() looks like :

Key('Parents', 'my_parent', 'Childs', 'my_child')    # the first pair is the parent?

my_deferred.py :

def a_function(key) :

    entity = ndb.Key(key)  # the pass entity.key does not work !!!!!

Giving exception : ValueError: Key() must have an even number of positional arguments.

    entity = ndb.Key('Childs', key.id(), parent = key.parent()).get() # this one works fine

I do not understand why the entity.key() method does not give me a key, which I can use directly? Or is there another way to get the entity, without “changing” the key. And I do not understand the ValueError excpetion.

Update : Thanks to Gregory

    entity = key.get()    # works fine
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:46:48+00:00Added an answer on June 17, 2026 at 9:46 am

    first, answering your code specific question, passing the key properly, it is not a callable:


    deferred.defer(my_deferred.a_function, entity.key)

    next, on the actual design of the code itself, there are some things that need tweaking.

    • the deferred api serializes your code, so there really is no need to re-query entity from the datastore. if you insist on this though, passing the entity.key to the deferred method, it’s already an instance of ndb.Key, so there’s no need to construct a new Key object.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I pass a variable $foo to a function. This input variable might be an
I am trying to pass a double-dimensional array to a function, but it throws
I pass an object literal to a function like this: pre( {model:'MUserTry'} ); I
I pass a string into this function: function linkify($text) { $text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)', '<a
Pass a integer 2 to this function and then return a integer which is
I tried to pass Array of javascript classes in $.post function, but in controller
How do I get the equivalent result of the following query in NDB? Entity.all(keys_only=True).fetch(20)
I pass my string value to one method but I can't get the stored
I need to pass some structure as function argument like this void myFunc(unsigned char
I'm trying to pass a char* and change it in another function but somehow

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.