Merge lp:~wgrant/storm/psycopg2-2.4-pgbouncer into lp:storm

Proposed by William Grant on 2012-04-05
Status: Merged
Merged at revision: 445
Proposed branch: lp:~wgrant/storm/psycopg2-2.4-pgbouncer
Merge into: lp:storm
Diff against target: 63 lines (+5/-19)
3 files modified
storm/databases/postgres.py (+4/-3)
tests/databases/postgres.py (+1/-9)
tests/helper.py (+0/-7)
To merge this branch: bzr merge lp:~wgrant/storm/psycopg2-2.4-pgbouncer
Reviewer Review Type Date Requested Status
Thomas Herve (community) 2012-04-05 Approve on 2012-04-27
Stuart Bishop 2012-04-05 Approve on 2012-04-05
Review via email: mp+100896@code.launchpad.net

Commit Message

Fix pgbouncer disconnect handling with psycopg2 2.4.

Description of the Change

Storm has a bit of a hack to catch and ignore a ProgrammingError raised by disconnection caused by pgbouncer shutdown. That works fine in oldish psycopg2 releases. But psycopg2 2.4 raises a plain DatabaseError, which propagates up and breaks tests and applications alike. This branch alters Storm to catch DatabaseError in general (ProgrammingError is a subclass), making it work in psycopg2 2.4 as well. I undisabled the relevant tests (they were being skipped when using 2.4 due to this bug). All tests pass on Lucid and Precise.

To post a comment you must log in.
Stuart Bishop (stub) wrote :

This looks good.

review: Approve
David Britton (davidpbritton) wrote :

Confirmed tests passing on precise. great!

Thomas Herve (therve) wrote :

Looks great, +1!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'storm/databases/postgres.py'
2--- storm/databases/postgres.py 2012-03-30 08:22:35 +0000
3+++ storm/databases/postgres.py 2012-04-05 00:14:19 +0000
4@@ -308,9 +308,10 @@
5
6 if isinstance(exc, disconnection_errors):
7 # When the connection is closed by a termination of pgbouncer, a
8- # ProgrammingError is raised. If the raw connection is closed we
9- # assume it's actually a disconnection.
10- if isinstance(exc, ProgrammingError):
11+ # DatabaseError or subclass with no message (depending on
12+ # psycopg2 version) is raised. If the raw connection is closed
13+ # we assume it's actually a disconnection.
14+ if isinstance(exc, DatabaseError):
15 if self._raw_connection.closed:
16 return True
17 msg = str(exc)
18
19=== modified file 'tests/databases/postgres.py'
20--- tests/databases/postgres.py 2012-03-30 08:22:35 +0000
21+++ tests/databases/postgres.py 2012-04-05 00:14:19 +0000
22@@ -39,7 +39,7 @@
23 import storm.info
24 storm # Silence lint.
25
26-from tests import has_fixtures, has_psycopg, has_subunit
27+from tests import has_fixtures, has_subunit
28 from tests.databases.base import (
29 DatabaseTest, DatabaseDisconnectionTest, UnsupportedDatabaseTest)
30 from tests.expr import column1, column2, column3, elem1, table1, TrackContext
31@@ -704,14 +704,6 @@
32 DisconnectionError, connection.execute,
33 "SELECT current_database()")
34
35- if has_psycopg:
36- import psycopg2
37- psycopg2_version = psycopg2.__version__.split(None, 1)[0]
38- if psycopg2_version in ("2.4", "2.4.1", "2.4.2"):
39- test_pgbouncer_stopped.skip = (
40- "Fails with pyscopg2 %s; see https://bugs.launchpad"
41- ".net/storm/+bug/900702.") % psycopg2_version
42-
43
44 if has_fixtures:
45 # Upgrade to full test case class with fixtures.
46
47=== modified file 'tests/helper.py'
48--- tests/helper.py 2011-12-07 11:57:07 +0000
49+++ tests/helper.py 2012-04-05 00:14:19 +0000
50@@ -66,13 +66,6 @@
51 result.startTest(self)
52 result.addSkip(self, "Test not supported")
53 return
54- # Skip if the test method has a non-None skip attribute.
55- skip = getattr(self._testMethod, "skip", None)
56- if skip is not None:
57- if hasattr(result, "addSkip"):
58- result.startTest(self)
59- result.addSkip(self, skip)
60- return
61 super(TestHelper, self).run(result)
62
63 def assertVariablesEqual(self, checked, expected):

Subscribers

People subscribed via source and target branches

to status/vote changes: