[Checkins] SVN: Zope3/trunk/ Attempt resolving issue http://www.zope.org/Collectors/Zope3-dev/655 by removing abort() calls from zope.app.form and modifying the publication object to not attempt a commit of doomed transactions.

Brian Sutherland jinty at web.de
Sun Mar 4 17:19:15 EST 2007


Log message for revision 72976:
  Attempt resolving issue http://www.zope.org/Collectors/Zope3-dev/655 by removing abort() calls from zope.app.form and modifying the publication object to not attempt a commit of doomed transactions.

Changed:
  U   Zope3/trunk/doc/CHANGES.txt
  U   Zope3/trunk/src/zope/app/form/browser/editview.py
  U   Zope3/trunk/src/zope/app/form/browser/formview.py
  U   Zope3/trunk/src/zope/app/form/browser/ftests/test_editview.py
  U   Zope3/trunk/src/zope/app/publication/zopepublication.py

-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt	2007-03-04 21:03:50 UTC (rev 72975)
+++ Zope3/trunk/doc/CHANGES.txt	2007-03-04 22:19:14 UTC (rev 72976)
@@ -102,6 +102,10 @@
         session data for anonymous requests. This reduces zodb
         conflicts for high-traffic sites with many anonymous requests.
 
+      - Change the publication object to abort the current transaction if
+        the trasaction was doomed. Related to:
+        http://www.zope.org/Collectors/Zope3-dev/655.
+
     Restructuring
 
       - Moved IBroken to zope.app.broken.interfaces to avoid cyclic imports.
@@ -355,10 +359,13 @@
       - Added ObjectModifiedEvent when a text file object is modified through
         the edit form in the ZMI.
 
+      - Resolved http://www.zope.org/Collectors/Zope3-dev/655 by having
+        zope.app.form use the transaction.doom() interface.
+
     Much thanks to everyone who contributed to this release:
 
       Jim Fulton, Dmitry Vasiliev, Martijn Faassen, Christian Theune, Wolfgang
-      Schnerring, Fred Drake, Marius Gedminas, Baiju M
+      Schnerring, Fred Drake, Marius Gedminas, Baiju M, Brian Sutherland
 
   ------------------------------------------------------------------
 

Modified: Zope3/trunk/src/zope/app/form/browser/editview.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/editview.py	2007-03-04 21:03:50 UTC (rev 72975)
+++ Zope3/trunk/src/zope/app/form/browser/editview.py	2007-03-04 22:19:14 UTC (rev 72976)
@@ -102,7 +102,7 @@
             except WidgetsError, errors:
                 self.errors = errors
                 status = _("An error occurred.")
-                transaction.abort()
+                transaction.doom()
             else:
                 setUpEditWidgets(self, self.schema, source=self.adapted,
                                  ignoreStickyValues=True, 

Modified: Zope3/trunk/src/zope/app/form/browser/formview.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/formview.py	2007-03-04 21:03:50 UTC (rev 72975)
+++ Zope3/trunk/src/zope/app/form/browser/formview.py	2007-03-04 22:19:14 UTC (rev 72976)
@@ -13,7 +13,7 @@
 ##############################################################################
 """Form View Classes
 
-$Id: editview.py 29143 2005-02-14 22:43:16Z srichter $
+$Id$
 """
 __docformat__ = 'restructuredtext'
 
@@ -76,7 +76,7 @@
             except WidgetsError, errors:
                 self.errors = errors
                 status = _("An error occurred.")
-                transaction.abort()
+                transaction.doom()
             else:
                 if changed:
                     status = self.setData(self.data)

Modified: Zope3/trunk/src/zope/app/form/browser/ftests/test_editview.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/ftests/test_editview.py	2007-03-04 21:03:50 UTC (rev 72975)
+++ Zope3/trunk/src/zope/app/form/browser/ftests/test_editview.py	2007-03-04 22:19:14 UTC (rev 72976)
@@ -24,6 +24,7 @@
 from zope.schema import TextLine
 from zope.traversing.api import traverse
 
+from zope.app.form.browser.editview import EditView
 from zope.app.form.testing import AppFormLayer
 from zope.app.form.browser.ftests.support import *
 from zope.app.testing.functional import BrowserTestCase
@@ -46,7 +47,7 @@
 
     def test_rollback_on_error(self):
         """Tests rollback when a widget error occurs.
-        
+
         When one or more errors are generated by input widgets, the current
         transaction should be rolledback to ensure object integrity.
         """
@@ -55,13 +56,25 @@
         self.getRootFolder()['foo'].optional_text = u'initial optional'
         transaction.commit()
 
-        # submit form with legal value for optional_text and invalid for 
+        # submit form with legal value for optional_text and invalid for
         # required_text
-        response = self.publish('/foo/edit.html', form={
-            'field.optional_text': u'',
-            'field.required_text': u'',
-            'UPDATE_SUBMIT': ''})
-        self.assertEqual(response.getStatus(), 200)
+        old_update = EditView.update
+        try:
+            def new_update(self):
+                # This update changes something after form validation has failed.
+                # Side effects like this should not be committed.
+                # http://www.zope.org/Collectors/Zope3-dev/655
+                result = old_update(self)
+                self.context.required_text = u'changed after form validation'
+                return result
+            EditView.update = new_update
+            response = self.publish('/foo/edit.html', form={
+                'field.optional_text': u'',
+                'field.required_text': u'',
+                'UPDATE_SUBMIT': ''})
+            self.assertEqual(response.getStatus(), 200)
+        finally:
+            EditView.update = old_update
 
         # confirm that one errors exists
         self.assert_(patternExists(

Modified: Zope3/trunk/src/zope/app/publication/zopepublication.py
===================================================================
--- Zope3/trunk/src/zope/app/publication/zopepublication.py	2007-03-04 21:03:50 UTC (rev 72975)
+++ Zope3/trunk/src/zope/app/publication/zopepublication.py	2007-03-04 22:19:14 UTC (rev 72976)
@@ -162,10 +162,12 @@
 
     def afterCall(self, request, ob):
         txn = transaction.get()
-        self.annotateTransaction(txn, request, ob)
+        if txn.isDoomed():
+            txn.abort()
+        else:
+            self.annotateTransaction(txn, request, ob)
+            txn.commit()
 
-        txn.commit()
-
     def endRequest(self, request, ob):
         endInteraction()
         notify(EndRequestEvent(ob, request))



More information about the Checkins mailing list