Refactor to use SIGNUP_FIELDS for username and email requirement checks, fix deprecated settings warnings
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!
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.0to65.5. - There are two
allauth_account_settings.EMAIL_REQUIREDin this file, you only updated one of them
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.
any updates?
Same PR already exists: https://github.com/iMerica/dj-rest-auth/pull/692
But this repo seems abandoned
Not abandoned. Feel free to tag me in PRs that require my attention.