[Checkins] SVN: zc.zservertracelog/trunk/ Fix KeyError: 'ZODB.interfaces.IConnection' on requests that do not have

Marius Gedminas marius at pov.lt
Tue Jan 10 01:13:52 UTC 2012


Log message for revision 124011:
  Fix KeyError: 'ZODB.interfaces.IConnection' on requests that do not have
  a ZODB connection in annotations (e.g. GET /++etc++process).
  
  

Changed:
  U   zc.zservertracelog/trunk/CHANGES.txt
  U   zc.zservertracelog/trunk/setup.py
  U   zc.zservertracelog/trunk/src/zc/zservertracelog/README.txt
  U   zc.zservertracelog/trunk/src/zc/zservertracelog/tracelog.py

-=-
Modified: zc.zservertracelog/trunk/CHANGES.txt
===================================================================
--- zc.zservertracelog/trunk/CHANGES.txt	2012-01-10 01:08:12 UTC (rev 124010)
+++ zc.zservertracelog/trunk/CHANGES.txt	2012-01-10 01:13:51 UTC (rev 124011)
@@ -1,6 +1,13 @@
 Changes
 =======
 
+1.3.1 (unreleased)
+------------------
+
+- Fix KeyError: 'ZODB.interfaces.IConnection' on requests that do not have
+  a ZODB connection in annotations (e.g. GET /++etc++process).
+
+
 1.3.0 (2010-04-08)
 ------------------
 

Modified: zc.zservertracelog/trunk/setup.py
===================================================================
--- zc.zservertracelog/trunk/setup.py	2012-01-10 01:08:12 UTC (rev 124010)
+++ zc.zservertracelog/trunk/setup.py	2012-01-10 01:13:51 UTC (rev 124011)
@@ -27,7 +27,7 @@
 
 setup(
     name=name,
-    version='0',
+    version='1.3.1dev',
     url='http://pypi.python.org/pypi/' + name,
     author='Zope Corporation and Contributors',
     author_email='zope3-dev at zope.org',

Modified: zc.zservertracelog/trunk/src/zc/zservertracelog/README.txt
===================================================================
--- zc.zservertracelog/trunk/src/zc/zservertracelog/README.txt	2012-01-10 01:08:12 UTC (rev 124010)
+++ zc.zservertracelog/trunk/src/zc/zservertracelog/README.txt	2012-01-10 01:13:51 UTC (rev 124011)
@@ -274,3 +274,28 @@
 For each database, the number of object's loaded and saved are
 provided.
 
+Since not all requests necessarily have a ZODB connection in their annotations
+(consider, e.g. ``GET /++etc++process``), let's make sure this works too
+
+    >>> class Request:
+    ...     def __init__(self, environ):
+    ...         self.get = environ.get
+    ...         self.annotations = {}
+    ...     # let this stub pretend to be a RequestEvent too
+    ...     request = property(lambda self: self)
+
+    >>> def dbapp2(environ, start_response):
+    ...     req = Request(environ)
+    ...     zc.zservertracelog.tracelog.before_traverse(req)
+    ...     zc.zservertracelog.tracelog.before_traverse(req)
+    ...     zc.zservertracelog.tracelog.request_ended(req)
+
+    >>> faux_app.app_hook = dbapp2
+
+    >>> invokeRequest(req1)
+    B 146419788 2012-01-10 03:10:05.501841 GET /test-req1
+    I 146419788 2012-01-10 03:10:05.502148 0
+    C 146419788 2012-01-10 03:10:05.502370
+    A 146419788 2012-01-10 03:10:05.502579 200 ?
+    E 146419788 2012-01-10 03:10:05.502782
+

Modified: zc.zservertracelog/trunk/src/zc/zservertracelog/tracelog.py
===================================================================
--- zc.zservertracelog/trunk/src/zc/zservertracelog/tracelog.py	2012-01-10 01:08:12 UTC (rev 124010)
+++ zc.zservertracelog/trunk/src/zc/zservertracelog/tracelog.py	2012-01-10 01:13:51 UTC (rev 124011)
@@ -174,7 +174,10 @@
     if tl is None:
         return
     if tl.transfer_counts is None:
-        connection = request.annotations['ZODB.interfaces.IConnection']
+        connection = request.annotations.get('ZODB.interfaces.IConnection')
+        # Not all requests have a ZODB connection; consider /++etc++process
+        if connection is None:
+            return
         tl.transfer_counts = dict(
             (name, connection.get_connection(name).getTransferCounts())
             for name in connection.db().databases)
@@ -189,7 +192,9 @@
     if not initial_counts:
         return
     tl.transfer_counts = None           # Reset in case of conflict
-    connection = request.annotations['ZODB.interfaces.IConnection']
+    connection = request.annotations.get('ZODB.interfaces.IConnection')
+    if connection is None:
+        return
     data = []
     for name in connection.db().databases:
         conn = connection.get_connection(name)



More information about the checkins mailing list