Handle POSError in 'query_utility' registry function
authorThierry Florac <thierry.florac@onf.fr>
Tue, 08 Nov 2016 12:23:11 +0100
changeset 69 0b859bda300e
parent 68 7f90df24ceca
child 70 ba0aefcd471a
Handle POSError in 'query_utility' registry function
src/pyams_utils/registry.py
--- a/src/pyams_utils/registry.py	Tue Nov 08 12:22:05 2016 +0100
+++ b/src/pyams_utils/registry.py	Tue Nov 08 12:23:11 2016 +0100
@@ -28,6 +28,7 @@
 # import packages
 from pyramid.events import subscriber
 from pyramid.threadlocal import manager
+from ZODB.POSException import POSError
 from zope.interface import implementedBy, providedBy
 
 
@@ -86,10 +87,13 @@
 
 def query_utility(provided, name='', default=None):
     """Query utility registered with given interface"""
-    for registry in get_registries():
-        utility = registry.queryUtility(provided, name, default)
-        if utility is not None:
-            return utility
+    try:
+        for registry in get_registries():
+            utility = registry.queryUtility(provided, name, default)
+            if utility is not None:
+                return utility
+    except POSError:
+        pass
     return default