Merge lp:~cjwatson/storm/fix-wrapped-exception-caching into lp:storm

Proposed by Colin Watson
Status: Merged
Merged at revision: 529
Proposed branch: lp:~cjwatson/storm/fix-wrapped-exception-caching
Merge into: lp:storm
Diff against target: 58 lines (+26/-3)
3 files modified
NEWS (+8/-0)
storm/database.py (+3/-3)
storm/tests/databases/base.py (+15/-0)
To merge this branch: bzr merge lp:~cjwatson/storm/fix-wrapped-exception-caching
Reviewer Review Type Date Requested Status
Simon Poirier (community) Approve
Review via email: mp+373348@code.launchpad.net

Commit message

Fix incorrect caching of wrapped DB-API exceptions.

To post a comment you must log in.
Revision history for this message
Simon Poirier (simpoir) wrote :

+1 It took some time and fiddling to wrap my head around the issue, but the change looks sane.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2019-09-20 07:15:20 +0000
3+++ NEWS 2019-09-27 19:24:08 +0000
4@@ -1,3 +1,11 @@
5+0.21.1 (XXXX-XX-XX)
6+===================
7+
8+Bug fixes
9+---------
10+
11+- Fix incorrect caching of wrapped DB-API exceptions (bug 1845702).
12+
13 0.21 (2019-09-20)
14 =================
15
16
17=== modified file 'storm/database.py'
18--- storm/database.py 2019-08-11 16:57:24 +0000
19+++ storm/database.py 2019-09-27 19:24:08 +0000
20@@ -622,10 +622,10 @@
21
22 @return: The combined exception type.
23 """
24- if wrapper_type not in self._exception_types:
25- self._exception_types[wrapper_type] = type(
26+ if dbapi_type.__name__ not in self._exception_types:
27+ self._exception_types[dbapi_type.__name__] = type(
28 dbapi_type.__name__, (dbapi_type, wrapper_type), {})
29- return self._exception_types[wrapper_type]
30+ return self._exception_types[dbapi_type.__name__]
31
32 def _wrap_exception(self, wrapper_type, exception):
33 """Wrap a DB-API exception as a StormError instance.
34
35=== modified file 'storm/tests/databases/base.py'
36--- storm/tests/databases/base.py 2019-09-17 09:35:10 +0000
37+++ storm/tests/databases/base.py 2019-09-27 19:24:08 +0000
38@@ -445,6 +445,21 @@
39 self.connection.unblock_access()
40 self.connection.execute("SELECT 1")
41
42+ def test_wrap_exception_subclasses(self):
43+ """Subclasses of the generic DB-API exception types are wrapped."""
44+ db_api_operational_error = getattr(
45+ self.database._exception_module, 'OperationalError')
46+ operational_error_types = [
47+ type(name, (db_api_operational_error,), {})
48+ for name in ('A', 'B')]
49+ for error_type in operational_error_types:
50+ error = error_type('error message')
51+ wrapped = self.database._wrap_exception(OperationalError, error)
52+ self.assertTrue(isinstance(wrapped, error_type))
53+ self.assertTrue(isinstance(wrapped, OperationalError))
54+ self.assertEqual(error_type.__name__, wrapped.__class__.__name__)
55+ self.assertEqual(('error message',), wrapped.args)
56+
57
58 class TwoPhaseCommitTest(object):
59

Subscribers

People subscribed via source and target branches

to status/vote changes: