Skip to content

Commit

Permalink
[fc] Repository: plone.testing
Browse files Browse the repository at this point in the history
Branch: refs/heads/master
Date: 2015-08-12T15:48:04+02:00
Author: Patrick Gerken () <patrick.gerken@zumtobelgroup.com>
Commit: plone/plone.testing@2c7d1b4

fix(ex_handling): Don't let finally block mask ex

We have a project with test code which utilizes collective.solr which
utilizes collective.indexing which pushes index operations to the
pre commit phase.
In our case an exception was then thrown during commit within
the zopeApp context.
closing the connection in the finally statement raised another exception
because of the unclean state left by the first exception.
This exception in the finally block totally masked the original
exception, hindering bug fixing.

Files changed:
M CHANGES.rst
M src/plone/testing/z2.py
Repository: plone.testing
Branch: refs/heads/master
Date: 2015-08-13T08:53:54+02:00
Author: Timo Stollenwerk (tisto) <tisto@plone.org>
Commit: plone/plone.testing@75488ff

Merge pull request #15 from plone/less_exception_masking

fix(ex_handling): Don't let finally block mask ex

Files changed:
M CHANGES.rst
M src/plone/testing/z2.py
  • Loading branch information
tisto committed Aug 13, 2015
1 parent 6f8be18 commit 4d35a17
Showing 1 changed file with 133 additions and 51 deletions.
184 changes: 133 additions & 51 deletions last_commit.txt
@@ -1,88 +1,170 @@
Repository: Products.CMFEditions
Repository: plone.testing


Branch: refs/heads/master
Date: 2015-08-13T06:30:38+02:00
Author: Timo Stollenwerk (tisto) <tisto@plone.org>
Commit: https://github.com/plone/Products.CMFEditions/commit/2ee4b79f597c046a2d466b4002c8e79c481628b4
Date: 2015-08-12T15:48:04+02:00
Author: Patrick Gerken () <patrick.gerken@zumtobelgroup.com>
Commit: https://github.com/plone/plone.testing/commit/2c7d1b4350bad8606869bc0b5c963d0bf140f98f

fix(ex_handling): Don't let finally block mask ex

Preparing release 2.2.14
We have a project with test code which utilizes collective.solr which
utilizes collective.indexing which pushes index operations to the
pre commit phase.
In our case an exception was then thrown during commit within
the zopeApp context.
closing the connection in the finally statement raised another exception
because of the unclean state left by the first exception.
This exception in the finally block totally masked the original
exception, hindering bug fixing.

Files changed:
M CHANGES.rst
M setup.py
M src/plone/testing/z2.py

diff --git a/CHANGES.rst b/CHANGES.rst
index c9dc90b..b01e397 100644
index fc10a43..95f4351 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -1,7 +1,7 @@
Changelog
=========

-2.2.14 (unreleased)
+2.2.14 (2015-08-13)
@@ -4,7 +4,8 @@ Changelog
4.0.15 (unreleased)
-------------------

- Do not call ndiff unless there is no html_diff. Removed strange
diff --git a/setup.py b/setup.py
index 233e57d..b3d44f5 100644
--- a/setup.py
+++ b/setup.py
@@ -2,7 +2,7 @@
-- Nothing changed yet.
+- Prevent exception masking in finally clause of zopeApp context
+ [do3cc]

from setuptools import setup, find_packages

-version = '2.2.14.dev0'
+version = '2.2.14'
4.0.14 (2015-07-29)
diff --git a/src/plone/testing/z2.py b/src/plone/testing/z2.py
index bc68839..04e00f8 100644
--- a/src/plone/testing/z2.py
+++ b/src/plone/testing/z2.py
@@ -253,18 +253,37 @@ def zopeApp(db=None, connection=None, environ=None):
if connection is None:
connection = app._p_jar

+ # exceptions in finally clauses can mask exceptions
+ # in the preceeding code block. So we catch
+ # every exception and throw it instead of the exception
+ # in the finally clause
+ inner_exception = None
try:
yield app
- except:
- transaction.abort()
+ except Exception, e:
+ inner_exception = e
+ try:
+ transaction.abort()
+ except Exception, e:
+ inner_exception = e
+ raise
raise
else:
- transaction.commit()
+ try:
+ transaction.commit()
+ except Exception, e:
+ inner_exception = e
finally:
- app.REQUEST.close()
-
- if closeConn:
- connection.close()
+ try:
+ app.REQUEST.close()
+
+ if closeConn:
+ connection.close()
+ except:
+ if inner_exception:
+ raise inner_exception
+ else:
+ raise

# Startup layer - you probably don't want to use this one directly

setup(name='Products.CMFEditions',
version=version,


Repository: Products.CMFEditions
Repository: plone.testing


Branch: refs/heads/master
Date: 2015-08-13T06:32:56+02:00
Date: 2015-08-13T08:53:54+02:00
Author: Timo Stollenwerk (tisto) <tisto@plone.org>
Commit: https://github.com/plone/Products.CMFEditions/commit/1379050476aad366291a88102d3f072d849ee4f4
Commit: https://github.com/plone/plone.testing/commit/75488ff60f5ea65f344cc173fa06a5252c8f1a58

Merge pull request #15 from plone/less_exception_masking

Back to development: 2.2.15
fix(ex_handling): Don't let finally block mask ex

Files changed:
M CHANGES.rst
M setup.py
M src/plone/testing/z2.py

diff --git a/CHANGES.rst b/CHANGES.rst
index b01e397..67dc8c7 100644
index fc10a43..95f4351 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -1,6 +1,12 @@
Changelog
=========

+2.2.15 (unreleased)
+-------------------
+
+- Nothing changed yet.
+
+
2.2.14 (2015-08-13)
@@ -4,7 +4,8 @@ Changelog
4.0.15 (unreleased)
-------------------

diff --git a/setup.py b/setup.py
index b3d44f5..6fbb708 100644
--- a/setup.py
+++ b/setup.py
@@ -2,7 +2,7 @@
-- Nothing changed yet.
+- Prevent exception masking in finally clause of zopeApp context
+ [do3cc]

from setuptools import setup, find_packages

-version = '2.2.14'
+version = '2.2.15.dev0'
4.0.14 (2015-07-29)
diff --git a/src/plone/testing/z2.py b/src/plone/testing/z2.py
index bc68839..04e00f8 100644
--- a/src/plone/testing/z2.py
+++ b/src/plone/testing/z2.py
@@ -253,18 +253,37 @@ def zopeApp(db=None, connection=None, environ=None):
if connection is None:
connection = app._p_jar

+ # exceptions in finally clauses can mask exceptions
+ # in the preceeding code block. So we catch
+ # every exception and throw it instead of the exception
+ # in the finally clause
+ inner_exception = None
try:
yield app
- except:
- transaction.abort()
+ except Exception, e:
+ inner_exception = e
+ try:
+ transaction.abort()
+ except Exception, e:
+ inner_exception = e
+ raise
raise
else:
- transaction.commit()
+ try:
+ transaction.commit()
+ except Exception, e:
+ inner_exception = e
finally:
- app.REQUEST.close()
-
- if closeConn:
- connection.close()
+ try:
+ app.REQUEST.close()
+
+ if closeConn:
+ connection.close()
+ except:
+ if inner_exception:
+ raise inner_exception
+ else:
+ raise

# Startup layer - you probably don't want to use this one directly

setup(name='Products.CMFEditions',
version=version,


0 comments on commit 4d35a17

Please sign in to comment.