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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:55:18+00:00 2026-06-16T03:55:18+00:00

I am trying to create a simple register for users. In order for that

  • 0

I am trying to create a simple register for users. In order for that register to be consistent, i cannot allow registering two users with the same username, on account to the eventual consistency of the default queries. I know the odds of that happening even with considerable traffic are almost 0, i want my implementation to be solid. I have implemented the ancestor queries that are supposed to be strongly consistent, yet when i publish my app and test it, i can make it register 2 users with the same username if i time it right.

def user_parent(group = 'default'):
key = ndb.Key('users', group)
return key

class User(ndb.Model):
    username = ndb.StringProperty(required = True)
    email = ndb.StringProperty(required = True)
    password = ndb.StringProperty(required = True)

@classmethod
def register(cls, username, password, email):
    return User(parent = user_parent(),
                username = username,
                password = password,
                email = email)

@classmethod
def by_name(cls, name):
    return User.query(User.username == name, ancestor = user_parent()).get()

@classmethod
def by_id(cls, uid):
    return User.get_by_id(uid, parent = user_parent()) 

@classmethod
def by_email(cls, email):
    logging.error(User.query(User.email == email, ancestor = user_parent()).get())
    return User.query(User.email == email, ancestor = user_parent()).get()

@classmethod
def login(cls, user, password):
    u = cls.by_name(user)
    if u and u.password == password:
        return u

I use reg_submit to perform an ajax request, i’m very new to programming and doubt this is the best solution to go about it, but the idea is that here i validate with calls made to the User model class.

    if reg_submit == 'True':
        reg_email = self.request.get('reg_email')
        reg_user = self.request.get('reg_user')
        reg_password = self.request.get('reg_password')
        reg_verify = self.request.get('reg_verify')

        valid = True
        if not valid_usr(reg_user):
            valid = False
            self.write('user')
            return
        if not valid_mail(reg_email):
            valid = False
            self.write('mail')
            return

        if User.by_email(reg_email):
            valid = False
            self.write('mail')
            return

        if User.by_name(reg_user):
            valid = False
            self.write('user')
            return

        if not valid_pass(reg_password):
            valid = False

        if reg_password != reg_verify:
            valid = False

        if valid:
            t = User.register(reg_user, reg_password, reg_email)
            t.put()
            self.login(t)
            self.redirect('/')

What i understand by making a query strongly consistent, is that the said query will not execute until every machine on which my database is replicated will be updated.

How do i achieve strongly consistent queries where two users, registering at the same time, with the same username, one of them, will not be able to do so.

  • 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-16T03:55:20+00:00Added an answer on June 16, 2026 at 3:55 am

    You need to run the check-query and the put inside a transaction. The docs for doing this with NDB are here.

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

Sidebar

Related Questions

I'm trying to create a very simple login for only one or two users,
I'm trying to create simple script that subscribes a user to a company calendar.
I setup a Paypal Sandbox account and am trying to create simple purchases through
I'm trying to create a simple widget to retrieve a users feeds, I have
I am trying to create a simple about page that uses JQuery click to
I'm trying to create a simple web page that resembles the following: I've got
I'm trying to create a simple two labeled list by creating two label label
Trying to create a simple form: <%@ Page Language=C# AutoEventWireup=true CodeBehind=register.aspx.cs Inherits=AlphaPack._Default MasterPageFile=MasterPages/Main.master title=Hi
I am trying to create a simple app for the iPad that with play
I am trying to create a SIMPLE plugin, no interface is necessary, that will

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.