NAMD / pypln.web

Web interface for PyPLN
http://pypln.org/
GNU General Public License v3.0
12 stars 8 forks source link

`IntegrityError` when creating a user that already exists. #114

Closed flavioamieiro closed 10 years ago

flavioamieiro commented 10 years ago

For some reason instead of warning the user that the username was taken, django_registration tried to insert the duplicate key in the database raising a IntegrityError. Here is the traceback (with some private information intentionally left out, but that should not be relevant to this problem).

Traceback (most recent call last):

  File "/srv/pypln/project/local/lib/python2.7/site-packages/Django-1.5.2-py2.7.egg/django/core/handlers/base.py", line 115, in get_response
    response = callback(request, *callback_args, **callback_kwargs)

  File "/srv/pypln/project/local/lib/python2.7/site-packages/Django-1.5.2-py2.7.egg/django/views/generic/base.py", line 68, in view
    return self.dispatch(request, *args, **kwargs)

  File "/srv/pypln/project/local/lib/python2.7/site-packages/django_registration-1.0-py2.7.egg/registration/views.py", line 79, in dispatch
    return super(RegistrationView, self).dispatch(request, *args, **kwargs)

  File "/srv/pypln/project/local/lib/python2.7/site-packages/Django-1.5.2-py2.7.egg/django/views/generic/base.py", line 86, in dispatch
    return handler(request, *args, **kwargs)

  File "/srv/pypln/project/local/lib/python2.7/site-packages/django_registration-1.0-py2.7.egg/registration/views.py", line 35, in post
    return self.form_valid(request, form)

  File "/srv/pypln/project/local/lib/python2.7/site-packages/django_registration-1.0-py2.7.egg/registration/views.py", line 82, in form_valid
    new_user = self.register(request, **form.cleaned_data)

  File "/srv/pypln/project/local/lib/python2.7/site-packages/django_registration-1.0-py2.7.egg/registration/backends/default/views.py", line 80, in register
    password, site)

  File "/srv/pypln/project/local/lib/python2.7/site-packages/Django-1.5.2-py2.7.egg/django/db/transaction.py", line 223, in inner
    return func(*args, **kwargs)

  File "/srv/pypln/project/local/lib/python2.7/site-packages/django_registration-1.0-py2.7.egg/registration/models.py", line 84, in create_inactive_user
    new_user = User.objects.create_user(username, email, password)

  File "/srv/pypln/project/local/lib/python2.7/site-packages/Django-1.5.2-py2.7.egg/django/contrib/auth/models.py", line 186, in create_user
    user.save(using=self._db)

  File "/srv/pypln/project/local/lib/python2.7/site-packages/Django-1.5.2-py2.7.egg/django/db/models/base.py", line 546, in save
    force_update=force_update, update_fields=update_fields)

  File "/srv/pypln/project/local/lib/python2.7/site-packages/Django-1.5.2-py2.7.egg/django/db/models/base.py", line 650, in save_base
    result = manager._insert([self], fields=fields, return_id=update_pk, using=using, raw=raw)

  File "/srv/pypln/project/local/lib/python2.7/site-packages/Django-1.5.2-py2.7.egg/django/db/models/manager.py", line 215, in _insert
    return insert_query(self.model, objs, fields, **kwargs)

  File "/srv/pypln/project/local/lib/python2.7/site-packages/Django-1.5.2-py2.7.egg/django/db/models/query.py", line 1675, in insert_query
    return query.get_compiler(using=using).execute_sql(return_id)

  File "/srv/pypln/project/local/lib/python2.7/site-packages/Django-1.5.2-py2.7.egg/django/db/models/sql/compiler.py", line 937, in execute_sql
    cursor.execute(sql, params)

  File "/srv/pypln/project/local/lib/python2.7/site-packages/Django-1.5.2-py2.7.egg/django/db/backends/postgresql_psycopg2/base.py", line 56, in execute
    six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e.args)), sys.exc_info()[2])

  File "/srv/pypln/project/local/lib/python2.7/site-packages/Django-1.5.2-py2.7.egg/django/db/backends/postgresql_psycopg2/base.py", line 54, in execute
    return self.cursor.execute(query, args)

IntegrityError: duplicate key value violates unique constraint "auth_user_username_key"
DETAIL:  Key (username)=(mediacloud) already exists.

<WSGIRequest
path:/accounts/register/,
[...]
 'HTTP_HOST': 'demo.pypln.org',
 'HTTP_ORIGIN': 'http://demo.pypln.org',
 'HTTP_REFERER': 'http://demo.pypln.org/accounts/register/',
[...]
 'PATH_INFO': u'/accounts/register/',
 'QUERY_STRING': '',
 'RAW_URI': '/accounts/register/',
[...]
 'REQUEST_METHOD': 'POST',
 'SCRIPT_NAME': u'',
 'SERVER_NAME': 'demo.pypln.org',
 'SERVER_PORT': '80',
 'SERVER_PROTOCOL': 'HTTP/1.0',
 'SERVER_SOFTWARE': 'gunicorn/17.5',
 'gunicorn.socket': <socket._socketobject object at 0x299aad0>,
 'wsgi.errors': <open file '<stderr>', mode 'w' at 0x7f1bd9705270>,
 'wsgi.file_wrapper': <class gunicorn.http.wsgi.FileWrapper at 0x1277668>,
 'wsgi.input': <gunicorn.http.body.Body object at 0x26f0490>,
 'wsgi.multiprocess': True,
 'wsgi.multithread': False,
 'wsgi.run_once': False,
 'wsgi.url_scheme': 'http',
 'wsgi.version': (1, 0)}>
fccoelho commented 10 years ago

I don't recall exactly what happened, but at first I tried to create a user named mediacloud using my gmail address, I think I got a 500 error. I thought that was because I already had an account with that email, then I tried to log into that account (fccoelho) it would give me access, the I tried the lost password link. I got an email to change my password but reminding me that the user was "mediacloud", so it appears that despite the 500 the account had been created. now the "mediacloud" account is active. but I have no Idea how the error above was generated.

flavioamieiro commented 10 years ago

I'll close this because we could not reproduce the error.