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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:20:17+00:00 2026-05-14T06:20:17+00:00

My User object that I want to create and store in the datastore has

  • 0

My User object that I want to create and store in the datastore has an email, and a username. How do I make sure when creating my User object that another User object doesn’t also have either the same email or the same username?

If I just do a query to see if any other users have already used the username or the email, then there could be a race condition.

UPDATE:
The solution I’m currently considering is to use the MemCache to implement a locking mechanism. I would acquire 2 locks before trying to store the User object in the datastore. First a lock that locks based on email, then another that locks based on username.

Since creating new User objects only happens at user registration time, and it’s even rarer that two people try to use either the same username or the same email, I think it’s okay to take the performance hit of locking.

I’m thinking of using the MemCache locking code that is here: http://appengine-cookbook.appspot.com/recipe/mutex-using-memcache-api/

What do you guys think?

  • 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-14T06:20:17+00:00Added an answer on May 14, 2026 at 6:20 am

    Try storing your User with their email as the key_name. This can be done in one simple step:

    MyUser.get_or_insert(email)
    

    Getting your MyUser by an email is also easy:

    MyUser.get_by_key_name(email)
    

    See this similar question: add properties to users google app engine

    So that solves the problem of two users with the same email. To do the same for usernames, perform the “get users with this username” query and the “insert a user with this username” in a transaction (this is what get_or_insert() does behind the scenes).

    You can catch a TransactionFailedError to find cases when another user “takes” that username during your transaction.

    You definitely don’t want to use a memcache mutex, since that while loop waiting for the lock to free up can spend a lot of your memcache API call quota.

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

Sidebar

Related Questions

I am trying to convert a VISUAL USER OBJECT that was once embedded on
I have a function that loads a user object from a web service asynchronously.
I have a NSTimer object that I need to invalidate if a user taps
Usecase: The user makes font customizations to an object on the design surface, that
I have the following code that loads a user's Active Directory DirectoryEntry object from
I have a form that is bind to an object, and when the user
Why is it that for user defined types when creating an array of objects
I've got the following situation: A User object has a Set of Permission objects
I am creating a web app that requires the use of a Java Object
In our project we need to store some object (User, for example) and also

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.