This is a weird problem that I am facing in my Django application.
Configuration :
- Python 3.6
- Django 2.0.6
- DB : Djongo (MongoDB connector : Djongo repository)
I have overwritten the create_superuser to:
def create_superuser(self, email, is_staff, password):
user = self.model(
email=email,
is_staff=True,
is_active=True,
)
user.set_password(password)
user.save(using=self._db)
return user
I am able to create the superuser successfully but I am not able to login into the admin page. Following is my traceback:
Internal Server Error: /admin/login/
Traceback (most recent call last):
File "/home/fractaluser/dev_eugenie/venv_eugenie/lib/python3.6/site-packages/django/core/handlers/exception.py", line 35, in inner
response = get_response(request)
File "/home/fractaluser/dev_eugenie/venv_eugenie/lib/python3.6/site-packages/django/core/handlers/base.py", line 128, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/fractaluser/dev_eugenie/venv_eugenie/lib/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/fractaluser/dev_eugenie/venv_eugenie/lib/python3.6/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "/home/fractaluser/dev_eugenie/venv_eugenie/lib/python3.6/site-packages/django/contrib/admin/sites.py", line 398, in login
return LoginView.as_view(**defaults)(request)
File "/home/fractaluser/dev_eugenie/venv_eugenie/lib/python3.6/site-packages/django/views/generic/base.py", line 69, in view
return self.dispatch(request, *args, **kwargs)
File "/home/fractaluser/dev_eugenie/venv_eugenie/lib/python3.6/site-packages/django/utils/decorators.py", line 62, in _wrapper
return bound_func(*args, **kwargs)
File "/home/fractaluser/dev_eugenie/venv_eugenie/lib/python3.6/site-packages/django/views/decorators/debug.py", line 76, in sensitive_post_parameters_wrapper
return view(request, *args, **kwargs)
File "/home/fractaluser/dev_eugenie/venv_eugenie/lib/python3.6/site-packages/django/utils/decorators.py", line 58, in bound_func
return func.__get__(self, type(self))(*args2, **kwargs2)
File "/home/fractaluser/dev_eugenie/venv_eugenie/lib/python3.6/site-packages/django/utils/decorators.py", line 62, in _wrapper
return bound_func(*args, **kwargs)
File "/home/fractaluser/dev_eugenie/venv_eugenie/lib/python3.6/site-packages/django/utils/decorators.py", line 142, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/home/fractaluser/dev_eugenie/venv_eugenie/lib/python3.6/site-packages/django/utils/decorators.py", line 58, in bound_func
return func.__get__(self, type(self))(*args2, **kwargs2)
File "/home/fractaluser/dev_eugenie/venv_eugenie/lib/python3.6/site-packages/django/utils/decorators.py", line 62, in _wrapper
return bound_func(*args, **kwargs)
File "/home/fractaluser/dev_eugenie/venv_eugenie/lib/python3.6/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "/home/fractaluser/dev_eugenie/venv_eugenie/lib/python3.6/site-packages/django/utils/decorators.py", line 58, in bound_func
return func.__get__(self, type(self))(*args2, **kwargs2)
File "/home/fractaluser/dev_eugenie/venv_eugenie/lib/python3.6/site-packages/django/contrib/auth/views.py", line 66, in dispatch
return super().dispatch(request, *args, **kwargs)
File "/home/fractaluser/dev_eugenie/venv_eugenie/lib/python3.6/site-packages/django/views/generic/base.py", line 89, in dispatch
return handler(request, *args, **kwargs)
File "/home/fractaluser/dev_eugenie/venv_eugenie/lib/python3.6/site-packages/django/views/generic/edit.py", line 141, in post
if form.is_valid():
File "/home/fractaluser/dev_eugenie/venv_eugenie/lib/python3.6/site-packages/django/forms/forms.py", line 179, in is_valid
return self.is_bound and not self.errors
File "/home/fractaluser/dev_eugenie/venv_eugenie/lib/python3.6/site-packages/django/forms/forms.py", line 174, in errors
self.full_clean()
File "/home/fractaluser/dev_eugenie/venv_eugenie/lib/python3.6/site-packages/django/forms/forms.py", line 377, in full_clean
self._clean_form()
File "/home/fractaluser/dev_eugenie/venv_eugenie/lib/python3.6/site-packages/django/forms/forms.py", line 404, in _clean_form
cleaned_data = self.clean()
File "/home/fractaluser/dev_eugenie/venv_eugenie/lib/python3.6/site-packages/django/contrib/auth/forms.py", line 195, in clean
self.user_cache = authenticate(self.request, username=username, password=password)
File "/home/fractaluser/dev_eugenie/venv_eugenie/lib/python3.6/site-packages/django/contrib/auth/__init__.py", line 70, in authenticate
user = _authenticate_with_backend(backend, backend_path, request, credentials)
File "/home/fractaluser/dev_eugenie/venv_eugenie/lib/python3.6/site-packages/django/contrib/auth/__init__.py", line 116, in _authenticate_with_backend
return backend.authenticate(*args, **credentials)
File "/home/fractaluser/dev_eugenie/venv_eugenie/lib/python3.6/site-packages/django/contrib/auth/backends.py", line 22, in authenticate
if user.check_password(password) and self.user_can_authenticate(user):
File "/home/fractaluser/dev_eugenie/venv_eugenie/lib/python3.6/site-packages/django/contrib/auth/base_user.py", line 111, in check_password
return check_password(raw_password, self.password, setter)
File "/home/fractaluser/dev_eugenie/venv_eugenie/lib/python3.6/site-packages/django/contrib/auth/hashers.py", line 42, in check_password
if password is None or not is_password_usable(encoded):
File "/home/fractaluser/dev_eugenie/venv_eugenie/lib/python3.6/site-packages/django/contrib/auth/hashers.py", line 25, in is_password_usable
if encoded is None or encoded.startswith(UNUSABLE_PASSWORD_PREFIX):
AttributeError: 'int' object has no attribute 'startswith'
This is very unusual (I understand what the error means) and I am not able to understand what is causing it or how I can fix it.
Were there other changes as well? I am not able to replicate this issue, if I change the
create_superuser
function to what you have posted, I can't even create a superuser. It just fails because the username is still being passed in, which is unexpected.But if you did happen to get this to run, it looks like the
password
argument might beNone
which is causing theset_password
function to callset_unusable_password
according to the documentation.However, to dig down to what the problem actually is more information would be needed.