Author: phd
Date: Mon Sep 30 08:26:40 2013
New Revision: 4661
Log:
Merged revision 4660 from branch 1.5:
when a PostgresConnection raises an exception the instance has
code/error attributes copied from psycopg2's pgcode/pgerror attributes.
Modified:
SQLObject/trunk/docs/News.txt
SQLObject/trunk/sqlobject/postgres/pgconnection.py
Modified: SQLObject/trunk/docs/News.txt
==============================================================================
--- SQLObject/trunk/docs/News.txt Mon Sep 30 08:09:01 2013 (r4660)
+++ SQLObject/trunk/docs/News.txt Mon Sep 30 08:26:40 2013 (r4661)
@@ -25,6 +25,9 @@
Minor features
--------------
+* When a PostgresConnection raises an exception the instance has
+ code/error attributes copied from psycopg2's pgcode/pgerror attributes.
+
* Encode unicode enum values to str.
* Removed setDeprecationLevel from the list of public functions.
Modified: SQLObject/trunk/sqlobject/postgres/pgconnection.py
==============================================================================
--- SQLObject/trunk/sqlobject/postgres/pgconnection.py Mon Sep 30 08:09:01 2013 (r4660)
+++ SQLObject/trunk/sqlobject/postgres/pgconnection.py Mon Sep 30 08:26:40 2013 (r4661)
@@ -6,9 +6,13 @@
from sqlobject.dberrors import *
class ErrorMessage(str):
- def __new__(cls, e):
- obj = str.__new__(cls, e[0])
- obj.code = None
+ def __new__(cls, e, append_msg=''):
+ obj = str.__new__(cls, e[0] + append_msg)
+ if e.__module__ == 'psycopg2':
+ obj.code = getattr(e, 'pgcode', None)
+ obj.error = getattr(e, 'pgerror', None)
+ else:
+ obj.code = obj.error = None
obj.module = e.__module__
obj.exception = e.__class__.__name__
return obj
@@ -139,7 +143,7 @@
else:
conn = self.module.connect(**self.dsn_dict)
except self.module.OperationalError, e:
- raise OperationalError("%s; used connection string %r" % (e, self.dsn))
+ raise OperationalError(ErrorMessage(e, "used connection string %r" % self.dsn))
# For printDebug in _executeRetry
self._connectionNumbers[id(conn)] = self._connectionCount
|