Skip to content

Commit 85bae29

Browse files
committed
Fix(pgconnection): Adapt Postgres exception handling to psycopg2 2.8
In the recent `psycopg2` errors are in `psycopg2.errors` module.
1 parent ed64be0 commit 85bae29

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

docs/News.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@ News
55
.. contents:: Contents:
66
:backlinks: none
77

8-
SQLObject 3.8.0 (master)
9-
========================
8+
SQLObject (master)
9+
==================
10+
11+
Minor features
12+
--------------
13+
14+
* Adapt Postgres exception handling to ``psycopg2`` version ``2.8``:
15+
in the recent ``psycopg2`` errors are in ``psycopg2.errors`` module.
1016

1117
SQLObject 3.7.1
1218
===============

sqlobject/postgres/pgconnection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
class ErrorMessage(str):
1212
def __new__(cls, e, append_msg=''):
1313
obj = str.__new__(cls, e.args[0] + append_msg)
14-
if e.__module__ == 'psycopg2':
14+
if hasattr(e, 'pgcode'): # psycopg2 or psycopg2.errors
1515
obj.code = getattr(e, 'pgcode', None)
1616
obj.error = getattr(e, 'pgerror', None)
1717
else:

0 commit comments

Comments
 (0)