Meine benutzerdefinierte adapters.py Datei enthält diese (und ich habe richtig es in settings.py verbunden, natürlich):django-allauth - kundenspezifische Adapter gibt Fehler: UNIQUE-Einschränkung fehlgeschlagen: main_user.email
from allauth.account.adapter import DefaultAccountAdapter
class AccountAdapter(DefaultAccountAdapter):
def save_user(self, request, user, form, commit=True):
data = form.cleaned_data
user.username = data.get('username')
user.email = data.get('email')
user.first_name = data.get('first_name')
user.last_name = data.get('last_name')
user.gender = data.get('gender')
user.birth_date = data.get('birth_date')
user.city = data.get('city')
user.country = data.get('country')
if 'password1' in data:
user.set_password(data.get('password1'))
else:
user.set_unusable_password()
self.populate_username(request, user)
if commit:
user.save()
return user
Der Fehler passiert irgendwo im Code in Allauth, und ich kann nicht herausfinden, warum. Ich habe das selbe wie in der ursprünglichen Adapterspeichermethode gemacht, aber aus irgendeinem Grund funktioniert es nicht für mein kundenspezifisches.
Hier ist ein voller Stack-Trace, wenn jemand, der sehen will, auch:
Traceback (most recent call last):
File "/home/mikisoft/django-dev/lib/python3.4/site-packages/django/core/handlers/base.py", line 149, in get_response
response = self.process_exception_by_middleware(e, request)
File "/home/mikisoft/django-dev/lib/python3.4/site-packages/django/core/handlers/base.py", line 147, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/mikisoft/django-dev/lib/python3.4/site-packages/django/views/generic/base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "/home/mikisoft/django-dev/lib/python3.4/site-packages/django/utils/decorators.py", line 67, in _wrapper
return bound_func(*args, **kwargs)
File "/home/mikisoft/django-dev/lib/python3.4/site-packages/django/views/decorators/debug.py", line 76, in sensitive_post_parameters_wrapper
return view(request, *args, **kwargs)
File "/home/mikisoft/django-dev/lib/python3.4/site-packages/django/utils/decorators.py", line 63, in bound_func
return func.__get__(self, type(self))(*args2, **kwargs2)
File "/home/mikisoft/django-dev/lib/python3.4/site-packages/allauth/account/views.py", line 177, in dispatch
return super(SignupView, self).dispatch(request, *args, **kwargs)
File "/home/mikisoft/django-dev/lib/python3.4/site-packages/allauth/account/views.py", line 66, in dispatch
**kwargs)
File "/home/mikisoft/django-dev/lib/python3.4/site-packages/allauth/account/views.py", line 155, in dispatch
**kwargs)
File "/home/mikisoft/django-dev/lib/python3.4/site-packages/django/views/generic/base.py", line 88, in dispatch
return handler(request, *args, **kwargs)
File "/home/mikisoft/django-dev/lib/python3.4/site-packages/allauth/account/views.py", line 82, in post
response = self.form_valid(form)
File "/home/mikisoft/django-dev/lib/python3.4/site-packages/allauth/account/views.py", line 192, in form_valid
self.user = form.save(self.request)
File "/home/mikisoft/django-dev/lib/python3.4/site-packages/allauth/account/forms.py", line 316, in save
self.custom_signup(request, user)
File "/home/mikisoft/django-dev/lib/python3.4/site-packages/allauth/account/forms.py", line 285, in custom_signup
custom_form.save(user)
File "/home/mikisoft/django-dev/lib/python3.4/site-packages/django/contrib/auth/forms.py", line 99, in save
user.save()
File "/home/mikisoft/django-dev/lib/python3.4/site-packages/django/contrib/auth/base_user.py", line 74, in save
super(AbstractBaseUser, self).save(*args, **kwargs)
File "/home/mikisoft/django-dev/lib/python3.4/site-packages/django/db/models/base.py", line 708, in save
force_update=force_update, update_fields=update_fields)
File "/home/mikisoft/django-dev/lib/python3.4/site-packages/django/db/models/base.py", line 736, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "/home/mikisoft/django-dev/lib/python3.4/site-packages/django/db/models/base.py", line 820, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "/home/mikisoft/django-dev/lib/python3.4/site-packages/django/db/models/base.py", line 859, in _do_insert
using=using, raw=raw)
File "/home/mikisoft/django-dev/lib/python3.4/site-packages/django/db/models/manager.py", line 122, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/mikisoft/django-dev/lib/python3.4/site-packages/django/db/models/query.py", line 1039, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File "/home/mikisoft/django-dev/lib/python3.4/site-packages/django/db/models/sql/compiler.py", line 1060, in execute_sql
cursor.execute(sql, params)
File "/home/mikisoft/django-dev/lib/python3.4/site-packages/django/db/backends/utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/home/mikisoft/django-dev/lib/python3.4/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/home/mikisoft/django-dev/lib/python3.4/site-packages/django/db/utils.py", line 95, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/mikisoft/django-dev/lib/python3.4/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/home/mikisoft/django-dev/lib/python3.4/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/home/mikisoft/django-dev/lib/python3.4/site-packages/django/db/backends/sqlite3/base.py", line 323, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.IntegrityError: UNIQUE constraint failed: main_user.email