Re: Connection errors
Oleg Broytman <[email protected]> Sun, 15 Sep 2013 17:52:15 +0400
| Newsgroups | gmane.comp.python.sqlobject |
|---|---|
| Message-ID | <[email protected]> |
On Fri, Sep 13, 2013 at 11:40:09AM -0300, Francisco Chiotta <[email protected]> wrote: > It would be great. Sure, I can test the results. The patch is attached. The code and error string are available: try: do_something() except OperationalError, e: print e.args[0].code print e.args[0].error Doesn't work for me, though -- pgcode/pgerror are always None. Perhaps I'm using old version of psycopg2 -- 2.4.5. Oleg. -- Oleg Broytman http://phdru.name/ [email protected] Programmers don't die, they just GOSUB without RETURN. ------------------------------------------------------------------------------ LIMITED TIME SALE - Full Year of Microsoft Training For Just $49.99! 1,500+ hours of tutorials including VisualStudio 2012, Windows 8, SharePoint 2013, SQL 2012, MVC 4, more. BEST VALUE: New Multi-Library Power Pack includes Mobile, Cloud, Java, and UX Design. Lowest price ever! Ends 9/22/13. http://pubads.g.doubleclick.net/gampad/clk?id=64545871&iu=/4140/ostg.clktrk _______________________________________________ sqlobject-discuss mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
pgcode.patch
(text/x-diff, 1.1 KB)
Index: sqlobject/postgres/pgconnection.py
===================================================================
--- sqlobject/postgres/pgconnection.py (revision 4658)
+++ sqlobject/postgres/pgconnection.py (working copy)
@@ -6,9 +6,12 @@
from sqlobject.dberrors import *
class ErrorMessage(str):
- def __new__(cls, e):
- obj = str.__new__(cls, e[0])
+ def __new__(cls, e, append_msg=''):
+ obj = str.__new__(cls, e[0] + append_msg)
obj.code = None
+ if e.__module__ == 'psycopg2':
+ obj.code = getattr(e, 'pgcode', None)
+ obj.error = getattr(e, 'pgerror', None)
obj.module = e.__module__
obj.exception = e.__class__.__name__
return obj
@@ -139,7 +142,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