Tivix/django-rest-auth

TypeError: 'PhoneNumber' object is not subscriptable

Opened this issue · 0 comments

models.py:

class CustomUser(AbstractUser):
    username = PhoneNumberField(unique=True)

payloads:

{
  "username": "+8801700000000",
  "password1": "demo",
  "password2": "demo",
  "email": "demo@demo.com",
}

response:

Internal Server Error: /api/rest-auth/registration/
Traceback (most recent call last):
  File "venv\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
    response = get_response(request)
  File "venv\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "venv\lib\site-packages\django\views\decorators\csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "venv\lib\site-packages\django\views\generic\base.py", line 70, in view
    return self.dispatch(request, *args, **kwargs)
  File "venv\lib\site-packages\django\utils\decorators.py", line 43, in _wrapper
    return bound_method(*args, **kwargs)
  File "venv\lib\site-packages\django\views\decorators\debug.py", line 89, in sensitive_post_parameters_wrapper
    return view(request, *args, **kwargs)
  File "venv\lib\site-packages\rest_auth\registration\views.py", line 46, in dispatch
    return super(RegisterView, self).dispatch(*args, **kwargs)
  File "venv\lib\site-packages\rest_framework\views.py", line 509, in dispatch
    response = self.handle_exception(exc)
  File "venv\lib\site-packages\rest_framework\views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
  File "venv\lib\site-packages\rest_framework\views.py", line 480, in raise_uncaught_exception
    raise exc
  File "venv\lib\site-packages\rest_framework\views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
  File "venv\lib\site-packages\rest_framework\generics.py", line 190, in post
    return self.create(request, *args, **kwargs)
  File "venv\lib\site-packages\rest_auth\registration\views.py", line 65, in create
    user = self.perform_create(serializer)
  File "venv\lib\site-packages\rest_auth\registration\views.py", line 73, in perform_create
    user = serializer.save(self.request)
  File "venv\lib\site-packages\rest_auth\registration\serializers.py", line 210, in save
    adapter.save_user(request, user, self)
  File "venv\lib\site-packages\allauth\account\adapter.py", line 242, in save_user
    self.populate_username(request, user)
  File "venv\lib\site-packages\allauth\account\adapter.py", line 209, in populate_username
    user_username(
  File "venv\lib\site-packages\allauth\account\utils.py", line 120, in user_username
    return user_field(user, app_settings.USER_MODEL_USERNAME_FIELD, *args)
  File "venv\lib\site-packages\allauth\account\utils.py", line 110, in user_field
    v = v[0:max_length]
TypeError: 'PhoneNumber' object is not subscriptable

Problems finally here

    if args:
        # Setter
        v = args[0]            <-------
        if v:
            v = v[0:max_length]
        setattr(user, field, v)

Any solution without str(args[0])?