From 6eb2e7c78f561d960c40516c32616ec55441689d Mon Sep 17 00:00:00 2001 From: Henrik Levkowetz Date: Thu, 22 Mar 2012 13:40:38 +0000 Subject: [PATCH] Avoid complications from trying to save user login time when running with readonly access to the database. - Legacy-Id: 4160 --- django/contrib/auth/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/django/contrib/auth/__init__.py b/django/contrib/auth/__init__.py index 9d24cc4f9..5244f5619 100644 --- a/django/contrib/auth/__init__.py +++ b/django/contrib/auth/__init__.py @@ -64,11 +64,15 @@ def login(request, user): Persist a user id and a backend in the request. This way a user doesn't have to reauthenticate on every request. """ + from MySQLdb import OperationalError if user is None: user = request.user # TODO: It would be nice to support different login methods, like signed cookies. user.last_login = datetime.datetime.now() - user.save() + try: + user.save() + except OperationalError: + pass if SESSION_KEY in request.session: if request.session[SESSION_KEY] != user.id: