GoogleCloudPlatform / webapp2

webapp2 is a framework for Google App Engine
https://webapp2.readthedocs.org
Other
142 stars 63 forks source link

auth: Rollback Unique DS entries if user.put() fails #82

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create a user model that will fail when put() is called on it. E.g.:

class CustomUser(webapp2_extras.appengine.auth.models.User):
  has_error = ndb.StringProperty(default=False)

2. call 

ok, user = CustomUser.create_user('some_fake_auth_id')

3. the line "user.put()" in create_user 
http://webapp-improved.appspot.com/_modules/webapp2_extras/appengine/auth/models
.html#User.create_user
will fail. 

4. The Unique datastore will hold an entry for CustomUser with 
'some_fake_auth_id', but CustomUser will be empty, because user creation failed.

What version of the product are you using? On what operating system?
App Engine / Python
- name: webapp2
  version: "2.5.1"

Please provide any additional information below.
Though this example the error is clearly on the programmer's side in providing 
a model that won't allow for it to be saved, there are other sources of errors 
(DeadLineExceededError e.g.) that will cause user.put() to fail. I think in 
that case, webapp2 should handle this scenario gracefully and rollback the 
changes it made to the Unique datastore.

Original issue reported on code.google.com by al...@pagewoo.com on 18 Jul 2013 at 6:28

gaborfeher commented 5 years ago

We have run into this issue during the following incident in our live application, using the latest of webapp2 in our GAE project. https://status.cloud.google.com/incident/cloud-datastore/19002

For the first try, our user has experienced an unsuccessful registration, because user.put() had failed. For their second try, the original username was already reserved, so they couldn't register using the original name.