#17601: Error code from database exception should not be lost during exception
handling (psycopg2)
-------------------------------------+-------------------------------------
     Reporter:  zimnyx               |                    Owner:  nobody
         Type:                       |                   Status:  new
  Cleanup/optimization               |                  Version:  master
    Component:  Database layer       |               Resolution:
  (models, ORM)                      |             Triage Stage:  Accepted
     Severity:  Normal               |      Needs documentation:  0
     Keywords:                       |  Patch needs improvement:  0
    Has patch:  0                    |                    UI/UX:  0
  Needs tests:  0                    |
Easy pickings:  0                    |
-------------------------------------+-------------------------------------

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>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/064.117e6e9f2275ea8ffc2a9678453ef5c2%40djangoproject.com?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to