Updated logging to avoid exception when request doesn't contain any principal
authorThierry Florac <thierry.florac@onf.fr>
Thu, 10 Jan 2019 17:20:58 +0100
changeset 152 e34b240ffe2a
parent 151 1e660bc4b40a
child 153 332bf391de71
Updated logging to avoid exception when request doesn't contain any principal
src/pyams_security/utility.py
--- a/src/pyams_security/utility.py	Fri Nov 16 15:21:54 2018 +0100
+++ b/src/pyams_security/utility.py	Thu Jan 10 17:20:58 2019 +0100
@@ -13,8 +13,6 @@
 __docformat__ = 'restructuredtext'
 
 import logging
-logger = logging.getLogger('PyAMS (security)')
-
 from functools import lru_cache
 
 from beaker.cache import cache_region
@@ -35,6 +33,9 @@
 from pyams_utils.wsgi import wsgi_environ_cache
 
 
+logger = logging.getLogger('PyAMS (security)')
+
+
 @implementer(ISecurityManager)
 class SecurityManager(Folder):
     """Security manager utility"""
@@ -268,9 +269,12 @@
 
     @request_property(key=None)
     def effective_principals(self, request, context=None):
-        logger.debug(">>> getting principals for principal {0} ({1}) on {2!r}".format(request.principal.title,
-                                                                                      request.principal.id,
-                                                                                      context or request.context))
+        try:
+            logger.debug(">>> getting principals for principal {0} ({1}) on {2!r}".format(request.principal.title,
+                                                                                          request.principal.id,
+                                                                                          context or request.context))
+        except AttributeError:
+            logger.debug(">>> getting principals for request {0} on {1!r}".format(request, context or request.context))
         principals = {Everyone}
         principal_id = self.unauthenticated_userid(request)
         if principal_id: