Skip to content

Conversation

Covenantmondei
Copy link

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!

@igor-wl
Copy link

igor-wl commented Jun 6, 2025

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

@MisterNox
Copy link

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.

@Mte90
Copy link

Mte90 commented Jul 31, 2025

any updates?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants