Opened 13 years ago

Closed 13 years ago

#18292 closed New feature (duplicate)

Database errors get mangled

Reported by: gcbirzan@… Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When using the Django wrapper around the database connection, all errors are mangled into two exceptions, DatabaseError and IntegrityError. The only trace of the original exception is in the message, which can be localised, and is not always reliable anyway.

This seems to be a design decision as instead of raising the correct exception, a DatabaseError is constructed with the same message: https://code.djangoproject.com/browser/django/trunk/django/db/backends/postgresql_psycopg2/base.py#L56

This makes it non-trivial (bordering on impossible) to do some database stuff through the default django db backends.

Change History (2)

comment:1 by Anssi Kääriäinen, 13 years ago

Triage Stage: UnreviewedAccepted
Type: BugNew feature

The only solution would be to add the original exception as a wrapped in Django's exception. Using this you could get the original exception by something like:

try:
    do_something()
except django.db.utils.IntegrityError as e:
    if isinstance(e.wrapped, ...

I can see the use of that. Not as nice as getting the real raw exception, but then again that can't be provided while keeping compatibility and unified database interface...

comment:2 by Carl Meyer, 13 years ago

Resolution: duplicate
Status: newclosed

Dupe of #15901

Note: See TracTickets for help on using tickets.
Back to Top