iMerica / dj-rest-auth

Authentication for Django Rest Framework
https://dj-rest-auth.readthedocs.io/en/latest/index.html
MIT License
1.69k stars 317 forks source link

AttributeError: 'EmailAddressManager' object has no attribute 'is_verified' #583

Open Aneemes opened 10 months ago

Aneemes commented 10 months ago

I'm trying to my Django MVT based project into REST API. It's based on Django 3.2, Python 3.6 and django-allauth 0.50.0. Followed your documentation and registered urls for registration as:

    url(r'^register/', RegisterView.as_view(), name="rest_register"),

Now, when i fill in the required details and post, the following error is thrown:

    if email and EmailAddress.objects.is_verified(email):
AttributeError: 'EmailAddressManager' object has no attribute 'is_verified'

Is it a compatibility issues or? Here's the whole traceback

Environment:

Request Method: POST
Request URL: http://127.0.0.1:8000/api/v2/register/

Django Version: 3.2.5
Python Version: 3.6.0
Installed Applications:
['jet',
 'django.contrib.admin',
 'django.contrib.sites',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.postgres.search',
 'allauth',
 'allauth.account',
 'allauth.socialaccount',
 'allauth.socialaccount.providers.twitter',
 'allauth.socialaccount.providers.google',
 'crispy_forms',
 'hitcount',
 'star_ratings',
 'analytical',
 'bootstrap_pagination',
 'admin_reorder',
 'django_cleanup',
 'rest_framework',
 'rest_framework.authtoken',
 'import_export',
 'captcha',
 'corsheaders',
 'geoip2',
 'dj_rest_auth',
 'dj_rest_auth.registration',

 ]
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'corsheaders.middleware.CorsMiddleware',
 'django.middleware.locale.LocaleMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'debug_toolbar.middleware.DebugToolbarMiddleware',
 'admin_reorder.middleware.ModelAdminReorder',
]

Traceback (most recent call last):
  File "C:\ep_v2\env\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
    response = get_response(request)
  File "C:\ep_v2\env\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\ep_v2\env\lib\site-packages\django\views\decorators\csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "C:\ep_v2\env\lib\site-packages\django\views\generic\base.py", line 70, in view
    return self.dispatch(request, *args, **kwargs)
  File "C:\ep_v2\env\lib\site-packages\django\utils\decorators.py", line 43, in _wrapper
    return bound_method(*args, **kwargs)
  File "C:\ep_v2\env\lib\site-packages\django\views\decorators\debug.py", line 89, in sensitive_post_parameters_wrapper
    return view(request, *args, **kwargs)
  File "C:\ep_v2\env\lib\site-packages\dj_rest_auth\registration\views.py", line 42, in dispatch
    return super().dispatch(*args, **kwargs)
  File "C:\ep_v2\env\lib\site-packages\rest_framework\views.py", line 509, in dispatch
    response = self.handle_exception(exc)
  File "C:\ep_v2\env\lib\site-packages\rest_framework\views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
  File "C:\ep_v2\env\lib\site-packages\rest_framework\views.py", line 480, in raise_uncaught_exception
    raise exc
  File "C:\ep_v2\env\lib\site-packages\rest_framework\views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
  File "C:\ep_v2\env\lib\site-packages\rest_framework\generics.py", line 190, in post
    return self.create(request, *args, **kwargs)
  File "C:\ep_v2\env\lib\site-packages\dj_rest_auth\registration\views.py", line 63, in create
    serializer.is_valid(raise_exception=True)
  File "C:\ep_v2\env\lib\site-packages\rest_framework\serializers.py", line 227, in is_valid
    self._validated_data = self.run_validation(self.initial_data)
  File "C:\ep_v2\env\lib\site-packages\rest_framework\serializers.py", line 426, in run_validation
    value = self.to_internal_value(data)
  File "C:\ep_v2\env\lib\site-packages\rest_framework\serializers.py", line 485, in to_internal_value
    validated_value = validate_method(validated_value)
  File "C:\ep_v2\env\lib\site-packages\dj_rest_auth\registration\serializers.py", line 241, in validate_email
    if email and EmailAddress.objects.is_verified(email):

Exception Type: AttributeError at /api/v2/register/
Exception Value: 'EmailAddressManager' object has no attribute 'is_verified'
ambrosekuo commented 10 months ago

Ensure your django-allauth is up to date or at least past v0.55.2, The changes in this PR https://github.com/iMerica/dj-rest-auth/pull/539 for is_verified requires the updated EmailAddressManager.

Aneemes commented 10 months ago

yes I figured it's a version issue of allauth and dj rest auth.