Skip to content

Commit c5f639a

Browse files
committed
Add InterfaceError to the default failures list (#36)
1 parent 07b340d commit c5f639a

11 files changed

+77
-35
lines changed

dbutils/persistent_db.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
prepare the session, e.g. ["set datestyle to german", ...].
4343
failures: an optional exception class or a tuple of exception classes
4444
for which the connection failover mechanism shall be applied,
45-
if the default (OperationalError, InternalError) is not adequate
45+
if the default (OperationalError, InterfaceError, InternalError)
46+
is not adequate for the used database module
4647
ping: an optional flag controlling when connections are checked
4748
with the ping() method if such a method is available
4849
(0 = None = never, 1 = default = whenever it is requested,
@@ -155,7 +156,8 @@ def __init__(
155156
the session, e.g. ["set datestyle to ...", "set time zone ..."]
156157
failures: an optional exception class or a tuple of exception classes
157158
for which the connection failover mechanism shall be applied,
158-
if the default (OperationalError, InternalError) is not adequate
159+
if the default (OperationalError, InterfaceError, InternalError)
160+
is not adequate for the used database module
159161
ping: determines when the connection should be checked with ping()
160162
(0 = None = never, 1 = default = whenever it is requested,
161163
2 = when a cursor is created, 4 = when a query is executed,

dbutils/pooled_db.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@
5757
the default value True always issues a rollback for safety's sake)
5858
failures: an optional exception class or a tuple of exception classes
5959
for which the connection failover mechanism shall be applied,
60-
if the default (OperationalError, InternalError) is not adequate
60+
if the default (OperationalError, InterfaceError, InternalError)
61+
is not adequate for the used database module
6162
ping: an optional flag controlling when connections are checked
6263
with the ping() method if such a method is available
6364
(0 = None = never, 1 = default = whenever fetched from the pool,
@@ -210,7 +211,8 @@ def __init__(
210211
True to always issue a rollback for safety's sake)
211212
failures: an optional exception class or a tuple of exception classes
212213
for which the connection failover mechanism shall be applied,
213-
if the default (OperationalError, InternalError) is not adequate
214+
if the default (OperationalError, InterfaceError, InternalError)
215+
is not adequate for the used database module
214216
ping: determines when the connection should be checked with ping()
215217
(0 = None = never, 1 = default = whenever fetched from the pool,
216218
2 = when a cursor is created, 4 = when a query is executed,

dbutils/steady_db.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ def connect(
117117
the session, e.g. ["set datestyle to german", "set time zone mez"]
118118
failures: an optional exception class or a tuple of exception classes
119119
for which the failover mechanism shall be applied, if the default
120-
(OperationalError, InternalError) is not adequate
120+
(OperationalError, InternalError, Interface) is not adequate
121+
for the used database module
121122
ping: determines when the connection should be checked with ping()
122123
(0 = None = never, 1 = default = when _ping_check() is called,
123124
2 = whenever a cursor is created, 4 = when a query is executed,
@@ -258,16 +259,20 @@ def _create(self):
258259
try:
259260
self._failures = (
260261
self._dbapi.OperationalError,
262+
self._dbapi.InterfaceError,
261263
self._dbapi.InternalError)
262264
except AttributeError:
263265
try:
264266
self._failures = (
265267
self._creator.OperationalError,
268+
self._creator.InterfaceError,
266269
self._creator.InternalError)
267270
except AttributeError:
268271
try:
269272
self._failures = (
270-
con.OperationalError, con.InternalError)
273+
con.OperationalError,
274+
con.InterfaceError,
275+
con.InternalError)
271276
except AttributeError:
272277
raise AttributeError(
273278
"Could not determine failure exceptions"

docs/changelog.html

+22-15
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
<h1 class="title">Changelog for DBUtils</h1>
1313

1414
<section id="section-1">
15+
<h2>3.0.1</h2>
16+
<p>DBUtils 3.0.1 was released on December 22, 2021.</p>
17+
<p>It includes <span class="docutils literal">InterfaceError</span> to the default list of exceptions
18+
for which the connection failover mechanism is applied.
19+
You can override this with the <span class="docutils literal">failures</span> parameter.</p>
20+
</section>
21+
<section id="section-2">
1522
<h2>3.0.0</h2>
1623
<p>DBUtils 3.0.0 was released on November 26, 2021.</p>
1724
<p>It is intended to be used with Python versions 3.6 to 3.10.</p>
@@ -20,31 +27,31 @@ <h2>3.0.0</h2>
2027
<li><p>Cease support for Python 2 and 3.5, minor optimizations.</p></li>
2128
</ul>
2229
</section>
23-
<section id="section-2">
30+
<section id="section-3">
2431
<h2>2.0.3</h2>
2532
<p>DBUtils 2.0.3 was released on November 26, 2021.</p>
2633
<p>Changes:</p>
2734
<ul class="simple">
2835
<li><p>Support Python version 3.10.</p></li>
2936
</ul>
3037
</section>
31-
<section id="section-3">
38+
<section id="section-4">
3239
<h2>2.0.2</h2>
3340
<p>DBUtils 2.0.2 was released on June 8, 2021.</p>
3441
<p>Changes:</p>
3542
<ul class="simple">
3643
<li><p>Allow using context managers for pooled connections.</p></li>
3744
</ul>
3845
</section>
39-
<section id="section-4">
46+
<section id="section-5">
4047
<h2>2.0.1</h2>
4148
<p>DBUtils 2.0.1 was released on April 8, 2021.</p>
4249
<p>Changes:</p>
4350
<ul class="simple">
4451
<li><p>Avoid &quot;name Exception is not defined&quot; when exiting.</p></li>
4552
</ul>
4653
</section>
47-
<section id="section-5">
54+
<section id="section-6">
4855
<h2>2.0</h2>
4956
<p>DBUtils 2.0 was released on September 26, 2020.</p>
5057
<p>It is intended to be used with Python versions 2.7 and 3.5 to 3.9.</p>
@@ -60,7 +67,7 @@ <h2>2.0</h2>
6067
<li><p>This changelog has been compiled from the former release notes.</p></li>
6168
</ul>
6269
</section>
63-
<section id="section-6">
70+
<section id="section-7">
6471
<h2>1.4</h2>
6572
<p>DBUtils 1.4 was released on September 26, 2020.</p>
6673
<p>It is intended to be used with Python versions 2.7 and 3.5 to 3.9.</p>
@@ -71,7 +78,7 @@ <h2>1.4</h2>
7178
inside a transaction.</p></li>
7279
</ul>
7380
</section>
74-
<section id="section-7">
81+
<section id="section-8">
7582
<h2>1.3</h2>
7683
<p>DBUtils 1.3 was released on March 3, 2018.</p>
7784
<p>It is intended to be used with Python versions 2.6, 2.7 and 3.4 to 3.7.</p>
@@ -80,12 +87,12 @@ <h2>1.3</h2>
8087
<li><p>This version now supports context handlers for connections and cursors.</p></li>
8188
</ul>
8289
</section>
83-
<section id="section-8">
90+
<section id="section-9">
8491
<h2>1.2</h2>
8592
<p>DBUtils 1.2 was released on February 5, 2017.</p>
8693
<p>It is intended to be used with Python versions 2.6, 2.7 and 3.0 to 3.6.</p>
8794
</section>
88-
<section id="section-9">
95+
<section id="section-10">
8996
<h2>1.1.1</h2>
9097
<p>DBUtils 1.1.1 was released on February 4, 2017.</p>
9198
<p>It is intended to be used with Python versions 2.3 to 2.7.</p>
@@ -99,7 +106,7 @@ <h2>1.1.1</h2>
99106
<li><p>Fixed a problem when running under Jython (reported by Vitaly Kruglikov).</p></li>
100107
</ul>
101108
</section>
102-
<section id="section-10">
109+
<section id="section-11">
103110
<h2>1.1</h2>
104111
<p>DBUtils 1.1 was released on August 14, 2011.</p>
105112
<p>Improvements:</p>
@@ -128,7 +135,7 @@ <h2>1.1</h2>
128135
<li><p>Fixed some minor issues with the <span class="docutils literal">DBUtilsExample</span> for Webware.</p></li>
129136
</ul>
130137
</section>
131-
<section id="section-11">
138+
<section id="section-12">
132139
<h2>1.0</h2>
133140
<p>DBUtils 1.0 was released on November 29, 2008.</p>
134141
<p>It is intended to be used with Python versions 2.2 to 2.6.</p>
@@ -161,7 +168,7 @@ <h2>1.0</h2>
161168
the MySQLdb module (problem reported by Gregory Pinero).</p></li>
162169
</ul>
163170
</section>
164-
<section id="section-12">
171+
<section id="section-13">
165172
<h2>0.9.4</h2>
166173
<p>DBUtils 0.9.4 was released on July 7, 2007.</p>
167174
<p>This release fixes a problem in the destructor code and has been supplemented
@@ -170,7 +177,7 @@ <h2>0.9.4</h2>
170177
in the last release, since you can now pass custom creator functions
171178
for database connections instead of DB-API 2 modules.</p>
172179
</section>
173-
<section id="section-13">
180+
<section id="section-14">
174181
<h2>0.9.3</h2>
175182
<p>DBUtils 0.9.3 was released on May 21, 2007.</p>
176183
<p>Changes:</p>
@@ -185,7 +192,7 @@ <h2>0.9.3</h2>
185192
Added Chinese translation of the User's Guide, kindly contributed by gashero.</p></li>
186193
</ul>
187194
</section>
188-
<section id="section-14">
195+
<section id="section-15">
189196
<h2>0.9.2</h2>
190197
<p>DBUtils 0.9.2 was released on September 22, 2006.</p>
191198
<p>It is intended to be used with Python versions 2.2 to 2.5.</p>
@@ -195,7 +202,7 @@ <h2>0.9.2</h2>
195202
storage engine. Accordingly, renamed <span class="docutils literal">SolidPg</span> to <span class="docutils literal">SteadyPg</span>.</p></li>
196203
</ul>
197204
</section>
198-
<section id="section-15">
205+
<section id="section-16">
199206
<h2>0.9.1</h2>
200207
<p>DBUtils 0.9.1 was released on May 8, 2006.</p>
201208
<p>It is intended to be used with Python versions 2.2 to 2.4.</p>
@@ -209,7 +216,7 @@ <h2>0.9.1</h2>
209216
<li><p>Improved the documentation and added a User's Guide.</p></li>
210217
</ul>
211218
</section>
212-
<section id="section-16">
219+
<section id="section-17">
213220
<h2>0.8.1 - 2005-09-13</h2>
214221
<p>DBUtils 0.8.1 was released on September 13, 2005.</p>
215222
<p>It is intended to be used with Python versions 2.0 to 2.4.</p>

docs/changelog.rst

+10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
Changelog for DBUtils
22
+++++++++++++++++++++
33

4+
5+
3.0.1
6+
=====
7+
8+
DBUtils 3.0.1 was released on December 22, 2021.
9+
10+
It includes ``InterfaceError`` to the default list of exceptions
11+
for which the connection failover mechanism is applied.
12+
You can override this with the ``failures`` parameter.
13+
414
3.0.0
515
=====
616

docs/main.de.html

+6-4
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,10 @@ <h3>PersistentDB (persistent_db)</h3>
282282
</li>
283283
<li><p><span class="docutils literal">setsession</span>: eine optionale Liste von SQL-Befehlen zur Initialisierung
284284
der Datenbanksitzung, z.B. <span class="docutils literal">[&quot;set datestyle to german&quot;, <span class="pre">...]</span></span></p></li>
285-
<li><p><span class="docutils literal">failures</span>: eine optionale Exception-Klasse oder ein Tupel von Exceptions
285+
<li><p><span class="docutils literal">failures</span>: eine optionale Exception-Klasse oder ein Tupel von Exceptions,
286286
bei denen die Ausfallsicherung zum Tragen kommen soll, falls die Vorgabe
287-
(OperationalError, InternalError) nicht geeignet sein sollte</p></li>
287+
(OperationalError, InterfaceError, InternalError) für das verwendete
288+
Datenbankadapter-Modul nicht geeignet sein sollte</p></li>
288289
<li><p><span class="docutils literal">ping</span>: mit diesem Parameter kann eingestellt werden, wann Verbindungen
289290
mit der <span class="docutils literal">ping()</span>-Methode geprüft werden, falls eine solche vorhanden ist
290291
(<span class="docutils literal">0</span> = <span class="docutils literal">None</span> = nie, <span class="docutils literal">1</span> = Standardwert = immer wenn neu angefragt,
@@ -371,9 +372,10 @@ <h3>PooledDB (pooled_db)</h3>
371372
in den Verbindungspool zurückgegeben werden (<span class="docutils literal">False</span> oder <span class="docutils literal">None</span>
372373
um mit <span class="docutils literal">begin()</span> gestartete Transaktionen zurückzurollen, der Standardwert
373374
<span class="docutils literal">True</span> rollt sicherheitshalber mögliche Transaktionen immer zurück)</p></li>
374-
<li><p><span class="docutils literal">failures</span>: eine optionale Exception-Klasse oder ein Tupel von Exceptions
375+
<li><p><span class="docutils literal">failures</span>: eine optionale Exception-Klasse oder ein Tupel von Exceptions,
375376
bei denen die Ausfallsicherung zum Tragen kommen soll, falls die Vorgabe
376-
(OperationalError, InternalError) nicht geeignet sein sollte</p></li>
377+
(OperationalError, InterfaceError, InternalError) für das verwendete
378+
Datenbankadapter-Modul nicht geeignet sein sollte</p></li>
377379
<li><p><span class="docutils literal">ping</span>: mit diesem Parameter kann eingestellt werden, wann Verbindungen
378380
mit der <span class="docutils literal">ping()</span>-Methode geprüft werden, falls eine solche vorhanden ist
379381
(<span class="docutils literal">0</span> = <span class="docutils literal">None</span> = nie, <span class="docutils literal">1</span> = Standardwert = immer wenn neu angefragt,

docs/main.de.rst

+6-4
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,10 @@ Parameter angeben müssen:
269269
* ``setsession``: eine optionale Liste von SQL-Befehlen zur Initialisierung
270270
der Datenbanksitzung, z.B. ``["set datestyle to german", ...]``
271271

272-
* ``failures``: eine optionale Exception-Klasse oder ein Tupel von Exceptions
272+
* ``failures``: eine optionale Exception-Klasse oder ein Tupel von Exceptions,
273273
bei denen die Ausfallsicherung zum Tragen kommen soll, falls die Vorgabe
274-
(OperationalError, InternalError) nicht geeignet sein sollte
274+
(OperationalError, InterfaceError, InternalError) für das verwendete
275+
Datenbankadapter-Modul nicht geeignet sein sollte
275276

276277
* ``ping``: mit diesem Parameter kann eingestellt werden, wann Verbindungen
277278
mit der ``ping()``-Methode geprüft werden, falls eine solche vorhanden ist
@@ -378,9 +379,10 @@ Parameter angeben müssen:
378379
um mit ``begin()`` gestartete Transaktionen zurückzurollen, der Standardwert
379380
``True`` rollt sicherheitshalber mögliche Transaktionen immer zurück)
380381

381-
* ``failures``: eine optionale Exception-Klasse oder ein Tupel von Exceptions
382+
* ``failures``: eine optionale Exception-Klasse oder ein Tupel von Exceptions,
382383
bei denen die Ausfallsicherung zum Tragen kommen soll, falls die Vorgabe
383-
(OperationalError, InternalError) nicht geeignet sein sollte
384+
(OperationalError, InterfaceError, InternalError) für das verwendete
385+
Datenbankadapter-Modul nicht geeignet sein sollte
384386

385387
* ``ping``: mit diesem Parameter kann eingestellt werden, wann Verbindungen
386388
mit der ``ping()``-Methode geprüft werden, falls eine solche vorhanden ist

docs/main.html

+4-2
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,8 @@ <h3>PersistentDB (persistent_db)</h3>
263263
prepare the session, e.g. <span class="docutils literal">[&quot;set datestyle to german&quot;, <span class="pre">...]</span></span></p></li>
264264
<li><p><span class="docutils literal">failures</span>: an optional exception class or a tuple of exception classes
265265
for which the connection failover mechanism shall be applied,
266-
if the default (OperationalError, InternalError) is not adequate</p></li>
266+
if the default (OperationalError, InterfaceError, InternalError)
267+
is not adequate for the used database module</p></li>
267268
<li><p><span class="docutils literal">ping</span>: an optional flag controlling when connections are checked
268269
with the <span class="docutils literal">ping()</span> method if such a method is available
269270
(<span class="docutils literal">0</span> = <span class="docutils literal">None</span> = never, <span class="docutils literal">1</span> = default = whenever it is requested,
@@ -340,7 +341,8 @@ <h3>PooledDB (pooled_db)</h3>
340341
the default value <span class="docutils literal">True</span> always issues a rollback for safety's sake)</p></li>
341342
<li><p><span class="docutils literal">failures</span>: an optional exception class or a tuple of exception classes
342343
for which the connection failover mechanism shall be applied,
343-
if the default (OperationalError, InternalError) is not adequate</p></li>
344+
if the default (OperationalError, InterfaceError, InternalError)
345+
is not adequate for the used database module</p></li>
344346
<li><p><span class="docutils literal">ping</span>: an optional flag controlling when connections are checked
345347
with the <span class="docutils literal">ping()</span> method if such a method is available
346348
(<span class="docutils literal">0</span> = <span class="docutils literal">None</span> = never, <span class="docutils literal">1</span> = default = whenever fetched from the pool,

docs/main.rst

+4-2
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ of ``persistent_db``, passing the following parameters:
250250

251251
* ``failures``: an optional exception class or a tuple of exception classes
252252
for which the connection failover mechanism shall be applied,
253-
if the default (OperationalError, InternalError) is not adequate
253+
if the default (OperationalError, InterfaceError, InternalError)
254+
is not adequate for the used database module
254255

255256
* ``ping``: an optional flag controlling when connections are checked
256257
with the ``ping()`` method if such a method is available
@@ -347,7 +348,8 @@ following parameters:
347348

348349
* ``failures``: an optional exception class or a tuple of exception classes
349350
for which the connection failover mechanism shall be applied,
350-
if the default (OperationalError, InternalError) is not adequate
351+
if the default (OperationalError, InterfaceError, InternalError)
352+
is not adequate for the used database module
351353

352354
* ``ping``: an optional flag controlling when connections are checked
353355
with the ``ping()`` method if such a method is available

tests/mock_db.py

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ class OperationalError(DatabaseError):
1515
pass
1616

1717

18+
class InterfaceError(DatabaseError):
19+
pass
20+
21+
1822
class InternalError(DatabaseError):
1923
pass
2024

tests/test_steady_db.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,12 @@ def test_connection_failures(self):
406406
db = SteadyDBconnect(dbapi, failures=dbapi.OperationalError)
407407
db.close()
408408
self.assertRaises(dbapi.InternalError, db.cursor)
409-
db = SteadyDBconnect(
410-
dbapi, failures=(dbapi.OperationalError, dbapi.InternalError))
409+
db = SteadyDBconnect(dbapi, failures=(
410+
dbapi.OperationalError, dbapi.InterfaceError))
411+
db.close()
412+
self.assertRaises(dbapi.InternalError, db.cursor)
413+
db = SteadyDBconnect(dbapi, failures=(
414+
dbapi.OperationalError, dbapi.InterfaceError, dbapi.InternalError))
411415
db.close()
412416
db.cursor()
413417

0 commit comments

Comments
 (0)