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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:40:32+00:00 2026-05-22T22:40:32+00:00

I am wondering about fetching records using Model.get_by_key_name() vs Model.get_by_id() For example, let’s say

  • 0

I am wondering about fetching records using Model.get_by_key_name() vs Model.get_by_id()

For example, let’s say I am returning some JSON that will be used to display a table of records, and for each record, there is a button to delete that record. Suppose I have model ‘Foo’ and model instance ‘foo’.

I believe I can associate each button with the appropriate record using either:

str(foo.key())  #suppose it eval's to "axhYm92ZZXJvY2tyDgsSCENhnb3J5GBQM"

or

foo.key().id()  #suppose it eval's to "57"

One of these values will make its way into an HTML form, and user may click the button which makes the request to delete the record with this key/id.

The request would then result in either:

Foo.get_by_key_name("axhYm92ZZXJvY2tyDgsSCENhnb3J5GBQM").delete()

or

Foo.get_by_id(57).delete()

Now, being the indecision-riddled ADHD programmer that I am, I need to know … which is the “right” way? They both seem to work, but are there circumstances that make one preferable to the other? Is there some advantage to using the ‘key’ way vs the ‘id’ way?

  • 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-22T22:40:32+00:00Added an answer on May 22, 2026 at 10:40 pm

    You’re confusing a Key name with the stringified Key. They’re different. A key’s name is something you give an entity via the reserved key_name property at construction time. If you don’t, the system will generate an id. An entity key can have either a name or an id, but not both.

    If you’ve intentionally stringified a Key, you reconstitute it by passing it back to the Key constructor.

    stringifiedKey = str(key)
    reconstitutedKey = db.Key(stringifiedKey)
    

    Assuming you really meant name vs. id, it’s a matter of whichever is more convenient. Any performance difference is going to be microscopic.

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

Sidebar

Related Questions

I wondering about how in T-SQL can I retrieve - let's say - 1/2
I'm just wondering about large projects - say an airlines reservation system, how many
I've been wondering about how hard it would be to write some Python code
Just wondering about the performance impact of copying very large php variables. For example
I'm wondering about a best practice using NHibernate, AutoMapper and ASP.NET MVC. Currently, i'm
I was wondering about the difference between using a Control’s Hide() method compared to
I wondering about sense of using XmlDocument class to processing a small XML files.
I was wondering about something. Lets say I have this piece of code: if
Wondering about using gzipped resources for my iOS app. The idea is to unzip
I've been wondering about best practices on creating a project in MVC, and let

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.