Author: phd
Date: Mon Sep 30 08:09:01 2013
New Revision: 4660
Log:
When a PostgresConnection raises an exception the instance has
code/error attributes copied from psycopg2's pgcode/pgerror attributes.
Modified:
SQLObject/branches/1.5/docs/News.txt
SQLObject/branches/1.5/sqlobject/postgres/pgconnection.py
Modified: SQLObject/branches/1.5/docs/News.txt
==============================================================================
--- SQLObject/branches/1.5/docs/News.txt Thu Aug 29 14:12:01 2013 (r4659)
+++ SQLObject/branches/1.5/docs/News.txt Mon Sep 30 08:09:01 2013 (r4660)
@@ -22,6 +22,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/branches/1.5/sqlobject/postgres/pgconnection.py
==============================================================================
--- SQLObject/branches/1.5/sqlobject/postgres/pgconnection.py Thu Aug 29 14:12:01 2013 (r4659)
+++ SQLObject/branches/1.5/sqlobject/postgres/pgconnection.py Mon Sep 30 08:09:01 2013 (r4660)
@@ -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
|