Opened 6 years ago

Closed 6 years ago

Last modified 4 years ago

#12702 closed (fixed)

Database exceptions problem in multi-db setups

Reported by: wkornewald 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:

Description

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 russellm 6 years ago.
First pass at unifying exceptions under multi-db

Download all attachments as: .zip

Change History (6)

comment:1 Changed 6 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Design 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 6 years ago by wkornewald

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 6 years ago by russellm

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 6 years ago by russellm

First pass at unifying exceptions under multi-db

comment:4 Changed 6 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to closed

(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 4 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 deleted

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