--
Ticket URL: <https://code.djangoproject.com/ticket/17601>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_docs: => 0
* needs_better_patch: => 0
* type: Uncategorized => Cleanup/optimization
* needs_tests: => 0
* stage: Unreviewed => Accepted
Comment:
Sure, all value-added information we can bring might be useful for the
poor debugging dev :-)
--
Ticket URL: <https://code.djangoproject.com/ticket/17601#comment:1>
Comment (by jaylett):
The bug filed against psycopg2 was closed, rightly. I think what is needed
(within Django) is a way of getting at the original exception given the
common wrapper, so that (in this case) it's possible to access `pgcode`
and particularly `diag` from the psycopg2 exception. In python 3 this is
available via `__cause__` (AIUI; I haven't actually used py3 in anger).
Could we just set `__cause__` whether we're running under py3 or not?
Something like (at [c36b75c814f068fcb722d46bd5e71cbaddf9bf2d]):
{{{
--- a/django/db/utils.py
+++ b/django/db/utils.py
@@ -91,8 +91,7 @@ class DatabaseErrorWrapper(object):
except AttributeError:
args = (exc_value,)
dj_exc_value = dj_exc_type(*args)
- if six.PY3:
- dj_exc_value.__cause__ = exc_value
+ dj_exc_value.__cause__ = exc_value
# Only set the 'errors_occurred' flag for errors that may
make
# the connection unusable.
if dj_exc_type not in (DataError, IntegrityError):
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/17601#comment:2>
* cc: james@… (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/17601#comment:3>
Comment (by aaugustin):
I suppose setting __cause__ unconditionally can't hurt...
--
Ticket URL: <https://code.djangoproject.com/ticket/17601#comment:4>
Comment (by jaylett):
I can't think of a way it would, since it doesn't exist at the moment.
(It's possible that poorly-written code might use it to assume it's
running under py3, but that seems a stretch.)
I'm not quite sure where we'd want to document this; probably a small note
in `ref/exceptions`?. (There are no tests that use `__cause__` as far as I
can tell, so I don't know if we need an explicit test case for this.)
--
Ticket URL: <https://code.djangoproject.com/ticket/17601#comment:5>
* owner: nobody => jaylett
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/17601#comment:6>
Comment (by jaylett):
Pull request 1241 (https://github.com/django/django/pull/1241) rather than
messing around with tiny patches in comments.
--
Ticket URL: <https://code.djangoproject.com/ticket/17601#comment:7>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/17601#comment:8>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"54485557855d58d9a5027511025d5ab22f721c6d"]:
{{{
#!CommitTicketReference repository=""
revision="54485557855d58d9a5027511025d5ab22f721c6d"
Fixed #17601 -- expose underlying db exceptions under py2
Use __cause__ to expose the underlying database exceptions even
under python 2.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/17601#comment:9>