My workaround is to do a
{{{
from django.contrib import auth
auth.signals.user_logged_in.disconnect(auth.models.update_last_login)
}}}
But we could make the signal handler more resilient. Something like this?
{{{
def update_last_login(sender, user, **kwargs):
if not hasattr(user, 'last_login'):
return
}}}
PR to follow...
--
Ticket URL: <https://code.djangoproject.com/ticket/26823>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* component: Uncategorized => contrib.auth
* needs_better_patch: => 0
* type: Uncategorized => Bug
* needs_tests: => 0
* needs_docs: => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/26823#comment:1>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/26823#comment:2>
Comment (by hjwp):
cf https://github.com/django/django/pull/6855
--
Ticket URL: <https://code.djangoproject.com/ticket/26823#comment:3>
* stage: Unreviewed => Accepted
Comment:
An alternative implementation I thought of would be to introspect the user
model and see if it has a `last_login` field and avoid connecting the
signal if not. I'm not sure it's feasible with
`user_logged_in.connect(update_last_login)` at the module level since
`get_user_model()` can't be called there, but maybe if the signal
connecting happened in `AuthConfig.ready()` that could work?
--
Ticket URL: <https://code.djangoproject.com/ticket/26823#comment:4>
* needs_better_patch: 0 => 1
Comment:
+1 to connect the signal in `ready()`
--
Ticket URL: <https://code.djangoproject.com/ticket/26823#comment:5>
Comment (by apollo13):
Signal connection in `ready()` should not be done lightly, this method
should be idempotent -- either just import a module from there or make
sure to set `dispatch_uid`
--
Ticket URL: <https://code.djangoproject.com/ticket/26823#comment:6>
Comment (by Linus Lewandowski):
[https://github.com/django/django/pull/8557 PR].
--
Ticket URL: <https://code.djangoproject.com/ticket/26823#comment:7>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/26823#comment:8>
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"eedc88bd4a8468c2a0daa8346c9b57183dd77782" eedc88bd]:
{{{
#!CommitTicketReference repository=""
revision="eedc88bd4a8468c2a0daa8346c9b57183dd77782"
Fixed #26823 -- Prevented update_last_login signal receiver from crashing
if User model doesn't have last_login field.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26823#comment:9>