﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
17601	Error code from database exception should not be lost during exception handling (psycopg2)	Piotr Czachur	James Aylett	"Here is a fragment from source:django/trunk/django/db/backends/postgresql_psycopg2/base.py?rev=17244#L50
{{{
    def execute(self, query, args=None):
        try:
            return self.cursor.execute(query, args)
        except Database.IntegrityError, e:
            raise utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2]
        except Database.DatabaseError, e:
            raise utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2]
}}}

In case of Psycopg2 and database exceptions, error code is set as psycopg2 exception propery called [http://initd.org/psycopg/docs/module.html#psycopg2.Error.pgcode ""pgcode""] instead of being passed as exception argument, so this way we're loosing info about ""pgcode"" which is valuable. Handling database exception by parsing error message is a bit awkward.

I'm not sure if other backends are affected by this issue, but I can investigate and provide a patch if we agree on this issue.


P.S.[[BR]]
I've just filled a bug in this subject against Psycopg2: http://psycopg.lighthouseapp.com/projects/62710-psycopg/tickets/96-pgcode-should-be-present-in-exceptionargs
If they fix it, this ticket will become ""worksforme""."	Cleanup/optimization	closed	Database layer (models, ORM)	dev	Normal	fixed		james@…	Accepted	1	0	0	0	0	0
