#15901: Django should wrap all PEP 249 exceptions in db.utils
-------------------------------------+-------------------------------------
     Reporter:  xiaket               |                    Owner:  nobody
         Type:  New feature          |                   Status:  new
    Component:  Database layer       |                  Version:  1.3
  (models, ORM)                      |               Resolution:
     Severity:  Normal               |             Triage Stage:  Accepted
     Keywords:                       |      Needs documentation:  0
    Has patch:  1                    |  Patch needs improvement:  0
  Needs tests:  0                    |                    UI/UX:  0
Easy pickings:  0                    |
-------------------------------------+-------------------------------------

Comment (by akaariai):

 I'm not sure how much it helps if the ABC issue will be fixed in a future
 Python 3 release. Django is going most likely to support 3.2, and if 3.2.0
 has this issue then it will be a big problem for the use of ABC module.
 Too bad, the ABC module solution looks like exactly what we would want...
 It seems hard to hack around this issue, as the problem is at C code
 level.

 If the ABC can't be used, then I think using this style would be good:
 {{{
 try:
     do_stuff()
 except Database.DatabaseError as e:
     exc = util.DatabaseError(*e.args)
     exc.__cause__ = e
     raise util.DatabaseError, exc, sys.exc_info()[2]
 }}}
 If I understand it correctly, everything works exactly as now but you will
 have the original exception available in the `__cause__`. It is not the
 perfect solution, but allows users to access the original exception if
 they really need. I think you can even write your little context manager
 which re-raises the `__cause__` exception if you really need it...

-- 
Ticket URL: <https://code.djangoproject.com/ticket/15901#comment:23>
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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to