Skip to content

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

Description

@brianelangston

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions