#29132: Incorrect update_last_login signal handler behavior when using custom
User
model with an arbitrary last_login attribute (not a Field instance)
-------------------------------------+-------------------------------------
Reporter: Mikhail | Owner: nobody
Porokhovnichenko |
Type: Bug | Status: new
Component: contrib.auth | Version: 2.0
Severity: Normal | Resolution:
Keywords: last_login, | Triage Stage:
update_last_login, signals, | Unreviewed
user_logged_in |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Mikhail Porokhovnichenko:
Old description:
> **Please note! It's not a #26823 duplicate, and it's just an issue
> related this one.**
>
> In the current implementation, a signal handler connects with a user
> model when this model has a `last_login` field.
>
> {{{
> #!python
> if hasattr(get_user_model(), 'last_login'):
> from .models import update_last_login
> user_logged_in.connect(update_last_login,
> dispatch_uid='update_last_login')
> }}}
>
> And it would work when there isn't a `last_login` attribute in the custom
> user model. But what if I've inherited my custom model from
> `AbstractUser` and dropped the `last_login` by setting it to `None`?
>
> {{{
> #!python
> class User(AbstractBaseUser):
> last_login = None # Drop ``last_login`` field off
> }}}
>
> Technically, the model has a ``last_login`` attribute, but it's not a
> field!
>
> Suggesting change the check condition something like that:
> {{{
> #!python
> last_login = getattr(get_user_model(), 'last_login', None)
> if last_login is not None:
> # ...
> }}}
> or even
> {{{
> #!python
> if isisintance(last_login, models.Field):
> # ...
> }}}
New description:
**Please note! It's not a #26823 duplicate, and it's just an issue
related this one.**
In the current implementation, a signal handler connects with a user model
when this model has a `last_login` field.
{{{
#!python
if hasattr(get_user_model(), 'last_login'):
from .models import update_last_login
user_logged_in.connect(update_last_login,
dispatch_uid='update_last_login')
}}}
And it would work when there isn't a `last_login` attribute in the custom
user model. But what if I've inherited my custom model from `AbstractUser`
and dropped the `last_login` by setting it to `None`?
{{{
#!python
class User(AbstractBaseUser):
last_login = None # Drop ``last_login`` field off
}}}
Technically, the model has a `last_login` attribute, but it's not a field!
Suggesting change the check condition something like that:
{{{
#!python
last_login = getattr(get_user_model(), 'last_login', None)
if last_login is not None:
# ...
}}}
or even
{{{
#!python
if isisintance(last_login, models.Field):
# ...
}}}
--
--
Ticket URL: <https://code.djangoproject.com/ticket/29132#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/067.2e253765df74a181a530d8396111e5a1%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.