Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backend.py user_pre_save assumes the user model will always have a "username" field #39

Open
brianelangston opened this issue Dec 14, 2019 · 0 comments

Comments

@brianelangston
Copy link

LoginAttemptLogger().reset(user.username)

In backend.py, in the "user_pre_save" receiver, the call to get the user's username is hard-coded to be a field called "username":

LoginAttemptLogger().reset(user.username)

This hard-coded assumption that all user models will have a username field is incorrect - the field is not guaranteed to exist when using a custom user models. For example, I'm implementing a customer user model that uses email address as it's unique key/surrogate username. The above line of code breaks when set "is_active" to True on a user in the Django admin and then saving their record.

I believe that line should be updated to use the "get_username" method that should exist on the user object (assuming the custom user model is set up correctly and is based on Django's AbstractBaseUser).

LoginAttemptLogger().reset(user.get_username())

As a workaround in the meantime, I've added a property to my custom user model that returns the value of "get_username" when "username" is referenced.

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

No branches or pull requests

1 participant