question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

IntegrityError duplicate key

See original GitHub issue

Hey guys,

Not entirely sure if this is a Sentry issue, a Django issue, or an issue with the plugin. On a clean Sentry install (v 8.8.0) with only this plugin installed (tested versions 2.0 and 2.2) and Django version 1.6.11, I am able to create a new local user no problem. However, when trying to log in using an LDAP account, I get the “Oops! Something went wrong” error on the web interface, and the log throws the following error and traceback:

2016-09-28_19:42:51.98684 Traceback (most recent call last):
2016-09-28_19:42:51.98686   File "/www/sentry/local/lib/python2.7/site-packages/sentry/../django/core/handlers/base.py", line 112, in get_response
2016-09-28_19:42:51.98686     response = wrapped_callback(request, *callback_args, **callback_kwargs)
2016-09-28_19:42:51.98686   File "/www/sentry/local/lib/python2.7/site-packages/sentry/../django/views/generic/base.py", line 69, in view
2016-09-28_19:42:51.98687     return self.dispatch(request, *args, **kwargs)
2016-09-28_19:42:51.98687   File "/www/sentry/local/lib/python2.7/site-packages/sentry/../django/utils/decorators.py", line 29, in _wrapper
2016-09-28_19:42:51.98688     return bound_func(*args, **kwargs)
2016-09-28_19:42:51.98688   File "/www/sentry/local/lib/python2.7/site-packages/sentry/../django/utils/decorators.py", line 99, in _wrapped_view
2016-09-28_19:42:51.98688     response = view_func(request, *args, **kwargs)
2016-09-28_19:42:51.98689   File "/www/sentry/local/lib/python2.7/site-packages/sentry/../django/utils/decorators.py", line 25, in bound_func
2016-09-28_19:42:51.98689     return func(self, *args2, **kwargs2)
2016-09-28_19:42:51.98689   File "/www/sentry/local/lib/python2.7/site-packages/sentry/web/frontend/base.py", line 188, in dispatch
2016-09-28_19:42:51.98690     return self.handle(request, *args, **kwargs)
2016-09-28_19:42:51.98691   File "/www/sentry/local/lib/python2.7/site-packages/sentry/../django/views/decorators/cache.py", line 52, in _wrapped_view_func
2016-09-28_19:42:51.98691     response = view_func(request, *args, **kwargs)
2016-09-28_19:42:51.98691   File "/www/sentry/local/lib/python2.7/site-packages/sentry/../django/db/transaction.py", line 371, in inner
2016-09-28_19:42:51.98692     return func(*args, **kwargs)
2016-09-28_19:42:51.98692   File "/www/sentry/local/lib/python2.7/site-packages/sentry/web/frontend/auth_organization_login.py", line 132, in handle
2016-09-28_19:42:51.98693     response = self.handle_basic_auth(request, organization)
2016-09-28_19:42:51.98693   File "/www/sentry/local/lib/python2.7/site-packages/sentry/web/frontend/auth_organization_login.py", line 67, in handle_basic_auth
2016-09-28_19:42:51.98693     elif login_form.is_valid():
2016-09-28_19:42:51.98694   File "/www/sentry/local/lib/python2.7/site-packages/sentry/../django/forms/forms.py", line 129, in is_valid
2016-09-28_19:42:51.98694     return self.is_bound and not bool(self.errors)
2016-09-28_19:42:51.98694   File "/www/sentry/local/lib/python2.7/site-packages/sentry/../django/forms/forms.py", line 121, in errors
2016-09-28_19:42:51.98695     self.full_clean()
2016-09-28_19:42:51.98695   File "/www/sentry/local/lib/python2.7/site-packages/sentry/../django/forms/forms.py", line 274, in full_clean
2016-09-28_19:42:51.98696     self._clean_form()
2016-09-28_19:42:51.98696   File "/www/sentry/local/lib/python2.7/site-packages/sentry/../django/forms/forms.py", line 300, in _clean_form
2016-09-28_19:42:51.98697     self.cleaned_data = self.clean()
2016-09-28_19:42:51.98697   File "/www/sentry/local/lib/python2.7/site-packages/sentry/web/forms/accounts.py", line 136, in clean
2016-09-28_19:42:51.98697     password=password)
2016-09-28_19:42:51.98698   File "/www/sentry/local/lib/python2.7/site-packages/sentry/../django/contrib/auth/__init__.py", line 49, in authenticate
2016-09-28_19:42:51.98698     user = backend.authenticate(**credentials)
2016-09-28_19:42:51.98699   File "/www/sentry/local/lib/python2.7/site-packages/django_auth_ldap/backend.py", line 167, in authenticate
2016-09-28_19:42:51.98700     user = ldap_user.authenticate(password)
2016-09-28_19:42:51.98701   File "/www/sentry/local/lib/python2.7/site-packages/django_auth_ldap/backend.py", line 339, in authenticate
2016-09-28_19:42:51.98701     self._get_or_create_user()
2016-09-28_19:42:51.98701   File "/www/sentry/local/lib/python2.7/site-packages/django_auth_ldap/backend.py", line 548, in _get_or_create_user
2016-09-28_19:42:51.98702     self._user, created = self.backend.get_or_create_user(username, self)
2016-09-28_19:42:51.98702   File "/www/sentry/local/lib/python2.7/site-packages/sentry/../sentry_ldap_auth/backend.py", line 29, in get_or_create_user
2016-09-28_19:42:51.98703     email=ldap_user.attrs.get('mail', ' ')[0] or '',
2016-09-28_19:42:51.98704   File "/www/sentry/local/lib/python2.7/site-packages/sentry/../django/db/models/manager.py", line 214, in update
2016-09-28_19:42:51.98704     return self.get_queryset().update(*args, **kwargs)
2016-09-28_19:42:51.98704   File "/www/sentry/local/lib/python2.7/site-packages/sentry/../django/db/models/query.py", line 493, in update
2016-09-28_19:42:51.98705     rows = query.get_compiler(self.db).execute_sql(None)
2016-09-28_19:42:51.98705   File "/www/sentry/local/lib/python2.7/site-packages/sentry/../django/db/models/sql/compiler.py", line 980, in execute_sql
2016-09-28_19:42:51.98705     cursor = super(SQLUpdateCompiler, self).execute_sql(result_type)
2016-09-28_19:42:51.98706   File "/www/sentry/local/lib/python2.7/site-packages/sentry/../django/db/models/sql/compiler.py", line 786, in execute_sql
2016-09-28_19:42:51.98706     cursor.execute(sql, params)
2016-09-28_19:42:51.98706   File "/www/sentry/local/lib/python2.7/site-packages/raven/contrib/django/client.py", line 112, in execute
2016-09-28_19:42:51.98707     return real_execute(self, sql, params)
2016-09-28_19:42:51.98707   File "/www/sentry/local/lib/python2.7/site-packages/sentry/../django/db/backends/util.py", line 53, in execute
2016-09-28_19:42:51.98710     return self.cursor.execute(sql, params)
2016-09-28_19:42:51.98712   File "/www/sentry/local/lib/python2.7/site-packages/sentry/../django/db/utils.py", line 99, in __exit__
2016-09-28_19:42:51.98713     six.reraise(dj_exc_type, dj_exc_value, traceback)
2016-09-28_19:42:51.98714   File "/www/sentry/local/lib/python2.7/site-packages/sentry/../django/db/backends/util.py", line 53, in execute
2016-09-28_19:42:51.98716     return self.cursor.execute(sql, params)
2016-09-28_19:42:51.98717   File "/www/sentry/local/lib/python2.7/site-packages/sentry/db/postgres/decorators.py", line 75, in inner
2016-09-28_19:42:51.98719     raise_the_exception(self.db, e)
2016-09-28_19:42:51.98720   File "/www/sentry/local/lib/python2.7/site-packages/sentry/db/postgres/decorators.py", line 73, in inner
2016-09-28_19:42:51.98722     return func(self, *args, **kwargs)
2016-09-28_19:42:51.98723   File "/www/sentry/local/lib/python2.7/site-packages/sentry/db/postgres/decorators.py", line 21, in inner
2016-09-28_19:42:51.98725     return func(self, *args, **kwargs)
2016-09-28_19:42:51.98726   File "/www/sentry/local/lib/python2.7/site-packages/sentry/db/postgres/decorators.py", line 95, in inner
2016-09-28_19:42:51.98728     six.reraise(exc_info[0], exc_info[0](msg), exc_info[2])
2016-09-28_19:42:51.98729   File "/www/sentry/local/lib/python2.7/site-packages/sentry/db/postgres/decorators.py", line 88, in inner
2016-09-28_19:42:51.98731     return func(self, sql, *args, **kwargs)
2016-09-28_19:42:51.98732   File "/www/sentry/local/lib/python2.7/site-packages/sentry/db/postgres/base.py", line 39, in execute
2016-09-28_19:42:51.98734     return self.cursor.execute(sql, params)
2016-09-28_19:42:51.98736 IntegrityError: IntegrityError('duplicate key value violates unique constraint "sentry_useremail_user_id_469ffbb142507df2_uniq"\nDETAIL:  Key (user_id, email)=(8, my@ldap.email) already exists.\n',)
2016-09-28_19:42:51.98737 SQL: UPDATE "sentry_useremail" SET "user_id" = %s, "email" = %s
2016-09-28_19:42:51.98911 19:42:51 [ERROR] django.request: Internal Server Error: /auth/login/sentry/ (status_code=500 request=<WSGIRequest
2016-09-28_19:42:51.98915 path:/auth/login/sentry/,
2016-09-28_19:42:51.98931 GET:<QueryDict: {}>,
2016-09-28_19:42:51.98932 POST:<QueryDict: {u'username': [u'myuser'], u'csrfmiddlewaretoken': [u'VQpi9JvWKHUjcwerWEwr6PslIpFws4yT'], u'password': [u'superSecurePass'], u'op': [u'login']}>,

The new user is not registered in the auth_user or sentry_useremail tables. Not really sure where to go with this. Thank you in advance for any help you can provide!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
allisteracommented, Oct 5, 2016

thanks @barronhagerman !

0reactions
allisteracommented, Oct 5, 2016

Downgrading the library to 2.0 seemed to have fixed the issue. The emails seem unique. I have the following mapping:

AUTH_LDAP_USER_ATTR_MAP = {
  'name': 'name',
  'email': 'mail'
}

Looking down the user list email addresses seem to get populated.

Read more comments on GitHub >

github_iconTop Results From Across the Web

IntegrityError duplicate key value violates unique constraint
It just threw the error saying duplicate-key-value-violates in the first line because the email was set to empty by default which was the...
Read more >
Django.db.utils.IntegrityError: duplicate key value violates ...
Hey, I get a weird error trying to save related objects. Basically documents related to a model. I have a Postgres backend, and...
Read more >
8575 (IntegrityError: duplicate key violates unique constraint)
ERROR: duplicate key value violates unique constraint "id_pk". And here's the fix: SELECT setval('test_keys_id_seq', (SELECT MAX(id) FROM test_keys)+1).
Read more >
django.db.utils.integrityerror: duplicate key value ... - You.com
Django : django.db.utils.IntegrityError: duplicate key value violates unique constraint "auth_permission_pkey" [ Beautify Your Computer : https://www.hows.te...
Read more >
IntegrityError, Duplicate key, MySQL 5, blank and unique
get an IntegrityError warning me of a duplicate key. Traceback (most recent call last): File "/home/fanfatale/src/django/django/core/handlers/base.py" in
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found