[Zope-Checkins] SVN: Zope/branches/2.9/ Call setDefaultSkin on new requests created as the result of ConflictError retries. This allows view lookups to continue to work during retry attempts.

Alec Mitchell apm13 at columbia.edu
Tue Sep 19 14:15:44 EDT 2006


Log message for revision 70238:
  Call setDefaultSkin on new requests created as the result of ConflictError retries.  This allows view lookups to continue to work during retry attempts.
  

Changed:
  U   Zope/branches/2.9/doc/CHANGES.txt
  U   Zope/branches/2.9/lib/python/ZPublisher/Publish.py
  U   Zope/branches/2.9/lib/python/ZPublisher/tests/testPublish.py

-=-
Modified: Zope/branches/2.9/doc/CHANGES.txt
===================================================================
--- Zope/branches/2.9/doc/CHANGES.txt	2006-09-19 17:46:01 UTC (rev 70237)
+++ Zope/branches/2.9/doc/CHANGES.txt	2006-09-19 18:15:43 UTC (rev 70238)
@@ -8,6 +8,9 @@
 
    Bugs fixed
 
+      - Call setDefaultSkin on new requests created as the result of
+        ConflictError retries.
+      
       - Collector #2189: Fix logging of errors during product refresh.
 
       - Collector #2185: Log username for FCGI requests.

Modified: Zope/branches/2.9/lib/python/ZPublisher/Publish.py
===================================================================
--- Zope/branches/2.9/lib/python/ZPublisher/Publish.py	2006-09-19 17:46:01 UTC (rev 70237)
+++ Zope/branches/2.9/lib/python/ZPublisher/Publish.py	2006-09-19 18:15:43 UTC (rev 70238)
@@ -159,6 +159,8 @@
             # Only reachable if Retry is raised and request supports retry.
             newrequest=request.retry()
             request.close()  # Free resources held by the request.
+            # Set the default layer/skin on the newly generated request
+            setDefaultSkin(newrequest)
             try:
                 return publish(newrequest, module_name, after_list, debug)
             finally:

Modified: Zope/branches/2.9/lib/python/ZPublisher/tests/testPublish.py
===================================================================
--- Zope/branches/2.9/lib/python/ZPublisher/tests/testPublish.py	2006-09-19 17:46:01 UTC (rev 70237)
+++ Zope/branches/2.9/lib/python/ZPublisher/tests/testPublish.py	2006-09-19 18:15:43 UTC (rev 70238)
@@ -1,3 +1,5 @@
+from zope.app.publication.browser import setDefaultSkin
+from zope.publisher.interfaces.browser import IDefaultBrowserLayer
 from ZPublisher import Retry
 from ZODB.POSException import ConflictError
 
@@ -118,6 +120,14 @@
         r.retry_count = self.retry_count
         return r
 
+class RequestWithSkinCheck(Request):
+    def traverse(self, path, validated_hook):
+        if IDefaultBrowserLayer.providedBy(self):
+            return Object()
+        else:
+            tracer.exceptions['__call__'] = [ValueError]
+            return Object()
+
 module_name = __name__
 after_list = [None]
 
@@ -263,6 +273,56 @@
     raising ConflictError from zpublisher_exception_hook
     abort
 
+    The request generator applies the default skin layer to the request.
+    We have a specially crafted request that tests this.  If the
+    request does not have the required interface it raises an
+    ValueError.  Let's see that this works as expected
+
+    >>> tracer.reset()
+    >>> request = RequestWithSkinCheck()
+    >>> setDefaultSkin(request)
+    >>> response = publish(request, module_name, after_list)
+    >>> tracer.showTracedPath()
+    begin
+    __call__
+    commit
+
+    Retries generate new request objects, the publisher needs to
+    ensure that the skin layer is applied to those as well. If the
+    skin layer is not applied to subsequent requests, an ValueError
+    would be raised here.
+
+    >>> tracer.reset()
+    >>> tracer.exceptions['commit'] = [ConflictError, ConflictError,
+    ...                                  ConflictError, ConflictError]
+    >>> request = RequestWithSkinCheck()
+    >>> setDefaultSkin(request)
+    >>> response = publish(request, module_name, after_list)
+    Traceback (most recent call last):
+    ...
+    ConflictError: database conflict error
+    >>> tracer.showTracedPath()
+    begin
+    __call__
+    commit
+    raising ConflictError from commit
+    abort
+    begin
+    __call__
+    commit
+    raising ConflictError from commit
+    abort
+    begin
+    __call__
+    commit
+    raising ConflictError from commit
+    abort
+    begin
+    __call__
+    commit
+    raising ConflictError from commit
+    abort
+
     """
     pass
 



More information about the Zope-Checkins mailing list