diff --git a/rest_registration/utils/users.py b/rest_registration/utils/users.py index 619a7bb..112c20c 100644 --- a/rest_registration/utils/users.py +++ b/rest_registration/utils/users.py @@ -34,6 +34,16 @@ from django.db.models import Field, ForeignObjectRel UserField = Union[Field[Any, Any], ForeignObjectRel, GenericForeignKey] + BaseUserAttrsProxy = AbstractBaseUser +else: + BaseUserAttrsProxy = object + + +class UserAttrsProxy(BaseUserAttrsProxy): + + def __init__(self, **kwargs) -> None: + super().__init__() + self.__dict__.update(kwargs) def authenticate_by_login_data( @@ -187,8 +197,11 @@ def build_initial_user(data: Dict[str, Any]) -> 'AbstractBaseUser': for field_name in user_field_names: if field_name in data: user_data[field_name] = data[field_name] - user_class = get_user_model() - return user_class(**user_data) + try: + user_class = get_user_model() + return user_class(**user_data) + except ValueError: + return UserAttrsProxy(**user_data) def get_user_field_names( diff --git a/tests/unit_tests/api/views/register/test_register.py b/tests/unit_tests/api/views/register/test_register.py index 6fc3902..8590f45 100644 --- a/tests/unit_tests/api/views/register/test_register.py +++ b/tests/unit_tests/api/views/register/test_register.py @@ -91,7 +91,6 @@ def test_ok( assert_valid_register_verification_email(sent_email, user, timer) -@pytest.mark.skip("TODO: Issue #259") @pytest.mark.django_db @override_rest_registration_settings({ 'REGISTER_SERIALIZER_CLASS': 'tests.testapps.custom_users.serializers.RegisterUserSerializer', # noqa: E501