Opened 7 years ago

Closed 7 years ago

Last modified 5 years ago

#12702 closed (fixed)

Database exceptions problem in multi-db setups

Reported by: Waldemar Kornewald Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Keywords:
Cc: Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


There are no common DatabaseException and IntegrityError classes since multi-db got committed. Django uses the default backend's exceptions. The problem is that every backend defines its own exception classes, so you can't catch an error raised by a secondary backend.

Attachments (1)

t12702-r12351.1.diff (12.7 KB) - added by Russell Keith-Magee 7 years ago.
First pass at unifying exceptions under multi-db

Download all attachments as: .zip

Change History (6)

comment:1 Changed 7 years ago by Russell Keith-Magee

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Triage Stage: UnreviewedDesign decision needed

In fairness, this isn't a multi-db problem - there has *never* been a common base class for DatabaseException or IntegrityError classes. multi-db means that you can trigger this problem in a single project; previously, you would have had to share a reusable app between two different databases.

comment:2 Changed 7 years ago by Waldemar Kornewald

Hmm, I don't understand what you want to say. Previously I would've just imported django.db.IntegrityError, for example. That's OK in a single-db setup (even with a reusable app), but not in a multi-db setup with the current backend code.

comment:3 Changed 7 years ago by Russell Keith-Magee

My point is that *none* of the backends raise django.db.IntegrityError - they raise psycopg.IntegrityError or cx_Oracle.IntegrityError or MySQLdb.IntegrityError. There isn't a base class to any of these exceptions, so there isn't any common behavior that you can rely on in the general case.

However, this problem has become slightly more pointed now that we have multiple databases. As you pointe out, django.db.DatabaseException points to the DatabaseException for the default database, which isn't especially helpful if you're in a multiple database vendor situation. We need to do something about this for 1.2 - I'm just not sure what. Suggestions welcome.

Changed 7 years ago by Russell Keith-Magee

Attachment: t12702-r12351.1.diff added

First pass at unifying exceptions under multi-db

comment:4 Changed 7 years ago by Russell Keith-Magee

Resolution: fixed
Status: newclosed

(In [12352]) Fixed #12702 -- Introduced a common implementation of DatabaseError and IntegrityError, so that database backends can (re)raise common error classes. Thanks for Waldemar Kornewald for the report.

comment:5 Changed 5 years ago by Jacob

milestone: 1.2

Milestone 1.2 deleted

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