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
=== modified file 'NEWS'
--- NEWS 2019-09-20 07:15:20 +0000
+++ NEWS 2019-09-27 19:24:08 +0000
@@ -1,3 +1,11 @@
10.21.1 (XXXX-XX-XX)
2===================
3
4Bug fixes
5---------
6
7- Fix incorrect caching of wrapped DB-API exceptions (bug 1845702).
8
10.21 (2019-09-20)90.21 (2019-09-20)
2=================10=================
311
412
=== modified file 'storm/database.py'
--- storm/database.py 2019-08-11 16:57:24 +0000
+++ storm/database.py 2019-09-27 19:24:08 +0000
@@ -622,10 +622,10 @@
622622
623 @return: The combined exception type.623 @return: The combined exception type.
624 """624 """
625 if wrapper_type not in self._exception_types:625 if dbapi_type.__name__ not in self._exception_types:
626 self._exception_types[wrapper_type] = type(626 self._exception_types[dbapi_type.__name__] = type(
627 dbapi_type.__name__, (dbapi_type, wrapper_type), {})627 dbapi_type.__name__, (dbapi_type, wrapper_type), {})
628 return self._exception_types[wrapper_type]628 return self._exception_types[dbapi_type.__name__]
629629
630 def _wrap_exception(self, wrapper_type, exception):630 def _wrap_exception(self, wrapper_type, exception):
631 """Wrap a DB-API exception as a StormError instance.631 """Wrap a DB-API exception as a StormError instance.
632632
=== modified file 'storm/tests/databases/base.py'
--- storm/tests/databases/base.py 2019-09-17 09:35:10 +0000
+++ storm/tests/databases/base.py 2019-09-27 19:24:08 +0000
@@ -445,6 +445,21 @@
445 self.connection.unblock_access()445 self.connection.unblock_access()
446 self.connection.execute("SELECT 1")446 self.connection.execute("SELECT 1")
447447
448 def test_wrap_exception_subclasses(self):
449 """Subclasses of the generic DB-API exception types are wrapped."""
450 db_api_operational_error = getattr(
451 self.database._exception_module, 'OperationalError')
452 operational_error_types = [
453 type(name, (db_api_operational_error,), {})
454 for name in ('A', 'B')]
455 for error_type in operational_error_types:
456 error = error_type('error message')
457 wrapped = self.database._wrap_exception(OperationalError, error)
458 self.assertTrue(isinstance(wrapped, error_type))
459 self.assertTrue(isinstance(wrapped, OperationalError))
460 self.assertEqual(error_type.__name__, wrapped.__class__.__name__)
461 self.assertEqual(('error message',), wrapped.args)
462
448463
449class TwoPhaseCommitTest(object):464class TwoPhaseCommitTest(object):
450465

Subscribers

People subscribed via source and target branches

to status/vote changes: