Search code examples
pythondjangodjango-rest-framework

AttributeError EmailAddressManager object has no attribute is_verified


I get the following error while attempting to a register a user with the help of DRF, dj-rest-auth and django-allauth:

AttributeError at /api/v1/dj-rest-auth/registration/
'EmailAddressManager' object has no attribute 'is_verified'

Here is the templates part of settings.py file:


TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [BASE_DIR / "templates"],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
                "django.template.context_processors.request",
            ],
        },
    },
]

EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"

SITE_ID = 1

and project level urls.py file:


urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('apps.pages.front.urls')),
    path('api/v1/', include("apps.contacts.api.urls")),
    path('api-auth/', include("rest_framework.urls")),
    path("api/v1/dj-rest-auth/", include("dj_rest_auth.urls")),
    path("api/v1/dj-rest-auth/registration/", include("dj_rest_auth.registration.urls")),
]

And just in case if order of installed apps matter, here is my installed_apps:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'whitenoise.runserver_nostatic',
    'django.contrib.staticfiles',
    'django.contrib.sites',

    "rest_framework",
    "corsheaders",
    "rest_framework.authtoken",
    "allauth",
    "allauth.account",
    "allauth.socialaccount",
    "dj_rest_auth",
    'dj_rest_auth.registration',
    'drf_spectacular',
    'django_filters',

    'apps.pages.apps.PagesConfig',
    'apps.accounts.apps.AccountsConfig',
    'apps.contacts.apps.ContactsConfig',
]

(i'm keeping my apps in a dedicated apps folder, and have created a custom user model)

Leaving the email field empty will successfully register a new user, but it won't work if i add an email.


Solution

  • This issue occurs when there is a version mismatch between your django, django-allauth, or dj-rest-auth packages. In my case, I was using the following versions:

    django = “^4.2.4”
    django-allauth = “^0.54.0”
    dj-rest-auth = “^5.0.2”
    

    To resolve the issue, I downgraded dj-rest-auth to version “^5.0.1”. I recommend upgrading all three packages to their latest versions and it should work as intended.