[pyramid] Get rid of a bare "except" in UpdateLoginTimeAuthenticationPolicy
authorDenis Laxalde <denis.laxalde@logilab.fr>
Mon, 30 Oct 2017 09:28:52 +0100
changeset 12224 5c066dc7307b
parent 12223 79d243a2f0c5
child 12225 a8ed10f80a85
[pyramid] Get rid of a bare "except" in UpdateLoginTimeAuthenticationPolicy Also refactor a bit the method to restrict the try/except block to the code for which we actually want to catch an exception (i.e. the cnx.execute() + cnx.commit()).
cubicweb/pyramid/auth.py
--- a/cubicweb/pyramid/auth.py	Mon Oct 30 09:25:22 2017 +0100
+++ b/cubicweb/pyramid/auth.py	Mon Oct 30 09:28:52 2017 +0100
@@ -121,16 +121,16 @@
         return ()
 
     def remember(self, request, principal, **kw):
-        try:
-            repo = request.registry['cubicweb.repository']
-            with repo.internal_cnx() as cnx:
+        repo = request.registry['cubicweb.repository']
+        with repo.internal_cnx() as cnx:
+            try:
                 cnx.execute(
                     "SET U last_login_time %(now)s WHERE U eid %(user)s", {
                         'now': datetime.datetime.now(),
                         'user': principal})
                 cnx.commit()
-        except:
-            log.exception("Failed to update last_login_time")
+            except Exception:
+                log.exception("Failed to update last_login_time")
         return ()
 
     def forget(self, request):