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 7625771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:14:09+00:00 2026-05-31T05:14:09+00:00

I don’t understand how google app engine for python’s Model.get_or_insert(key_name, **kwds) method works. From

  • 0

I don’t understand how google app engine for python’s Model.get_or_insert(key_name, **kwds) method works.

From my understanding, all datastore operations inside a transaction must be ancestor queries. However, I don’t see how the documentation for Model.get_or_insert(key_name, **kwds) is an ancestor query. For the following example, since ‘parent’ is not specified in the arguments for the last line, wouldn’t the result of parent=kwds.get('parent') in the second line be None, thus negating the query as an ancestor query?:

def txn(key_name, **kwds):
    entity = Story.get_by_key_name(key_name, parent=kwds.get('parent')) # parent is not defined?
    if entity is None:
        entity = Story(key_name=key_name, **kwds)
        entity.put()
    return entity

def get_or_insert(key_name, **kwargs):
    return db.run_in_transaction(txn, key_name, **kwargs)

get_or_insert('some key', title="The Three Little Pigs")  # no parent specified

(link to documentation)

I’m not trying to split hairs here, I’m just having trouble understanding how to properly use transactions in my own application and was looking to this documentation to augment my understanding.

Thanks so much for your help!

  • 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-05-31T05:14:10+00:00Added an answer on May 31, 2026 at 5:14 am

    You need ancestor queries to guarantee atomicity in a transaction that involves multiple entities. All the entities in the transaction need to share the same ancestor. Model.get_or_insert() only retrieves one entity, which obviously shares the same ancestor with itself.

    Key paths/ancestors determine how data is stored in the App Engine datastore. Entities with a common ancestor are stored on the same database shard, making it easier to implement atomic transactions without synchronizing between shards.

    If you’re using the HRD, which you probably are at this point, Cross Group transactions are available too, although I’m not too certain on how they work behind the scenes.
    http://code.google.com/appengine/docs/python/datastore/overview.html#Cross_Group_Transactions

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't think that I'm mad, I understand how php works! That being said. I
I don't have any experience in updating a Rails app and when I google
Don't know how to google for such, but is there a way to query
I don't know: if this works. if it's a good idea. what it is
Don't know what's wrong here, when I run the application it says Specified method
Don't know where else to ask, but from one day to the other my
don't understand: in my controller: @json = User.all.to_gmaps4rails do |user| \Title\: \#{user.email}\ end in
Don't understand, if Data.Map is and [] is. I found this out while wondering
I don't like Jackson. I want to use ajax but with Google Gson. So
Don't ask me why but i can't use this method because I need to

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.