dj-rest-auth icon indicating copy to clipboard operation
dj-rest-auth copied to clipboard

Refactor to use SIGNUP_FIELDS for username and email requirement checks, fix deprecated settings warnings

Open Covenantmondei opened this issue 6 months ago • 5 comments

Replaced deprecated USERNAME_REQUIRED and EMAIL_REQUIRED usage with the recommended SIGNUP_FIELDS approach from django-allauth. Fixes warnings when using updated versions of django-allauth.

This avoids deprecation warnings in recent versions of the package.

@iMerica 👋 — let me know if this approach works. Happy to help further!

Covenantmondei avatar May 30 '25 09:05 Covenantmondei

I'm not a maintainer but I see some issue with this PR:

  • This approach means that it would only work for django-alluth 65.5+ in which case you also need to update all project's requirement files from minimum version 64.0 to 65.5.
  • There are two allauth_account_settings.EMAIL_REQUIRED in this file, you only updated one of them

igor-wl avatar Jun 06 '25 08:06 igor-wl

Maybe something like this makes more sense to stay backwards compatible:

# registration/serializers.py
from importlib.metadata import version
from packaging.version import parse as parse_version
import warnings

try:
    allauth_version = parse_version(version("django-allauth"))
    if allauth_version < parse_version("65.6.0"):
        EMAIL_REQUIRED = allauth_account_settings.EMAIL_REQUIRED
        USERNAME_REQUIRED = allauth_account_settings.USERNAME_REQUIRED
    else:
        EMAIL_REQUIRED = allauth_account_settings.SIGNUP_FIELDS.get('email', {}).get('required', True)
        USERNAME_REQUIRED = allauth_account_settings.SIGNUP_FIELDS.get('username', {}).get('required', True)
except Exception as e:
    warnings.warn(
        f"Failed to import allauth settings: {e}. ",
        ImportWarning,
    )
    EMAIL_REQUIRED = True
    USERNAME_REQUIRED = True

Of course we would need to change the respective sections with the new variable EMAIL_REQUIRED and USERNAME_REQUIRED.

MisterNox avatar Jul 16 '25 12:07 MisterNox

any updates?

Mte90 avatar Jul 31 '25 11:07 Mte90

Same PR already exists: https://github.com/iMerica/dj-rest-auth/pull/692

But this repo seems abandoned

codedoga avatar Nov 07 '25 19:11 codedoga

Not abandoned. Feel free to tag me in PRs that require my attention.

iMerica avatar Nov 07 '25 19:11 iMerica