#16948: Django DB backends hid information in database exceptions ---------------------------+---------------------------------------------- Reporter: jamesh | Owner: nobody Type: Uncategorized | Status: new Milestone: | Component: Database layer (models, ORM) Version: SVN | Severity: Normal Keywords: | Triage Stage: Unreviewed Has patch: 0 | Easy pickings: 0 UI/UX: 0 | ---------------------------+---------------------------------------------- The Django DB backends replace the exceptions raised by the underlying adapter with standard ones from django.db.utils.
I understand the reason for doing this (provide standard exceptions that calling code can catch), but it can lose information provided by those exceptions. For example, the psycopg2 adapter exposes the SQL error code as a "code" attribute on exceptions, and this is lost. Perhaps using the same strategy as Storm would help: rather than catching the adapter's exceptions and re-raising equivalent standard ones, it patches the adapter's exceptions so that they subclass from the standard ones. This could be done with a method like the following: {{{ def install_exceptions(module): if not isinstance(module.DatabaseError, django.db.utils.DatabaseError): module.DatabaseError.__bases__ += (django.db.utils.DatabaseError,) if not isinstance(module.IntegrityError, django.db.utils.IntegrityError): module.IntegrityError.__bases__ += (django.db.utils.IntegrityError,) }}} Once the adapter's exceptions have been patched it would no longer be necessary to wrap the adapter's cursors, since the standard cursor would raise exceptions that could be caught by generic code. -- Ticket URL: <https://code.djangoproject.com/ticket/16948> 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 django-updates@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.