Opened 7 years ago

Closed 7 years ago

#18292 closed New feature (duplicate)

Database errors get mangled

Reported by: gcbirzan@… Owned by: nobody
Component: Database layer (models, ORM) Version: master
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


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:

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

Change History (2)

comment:1 Changed 7 years ago by Anssi Kääriäinen

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:

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 Changed 7 years ago by Carl Meyer

Resolution: duplicate
Status: newclosed

Dupe of #15901

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