Opened 13 years ago

Closed 12 years ago

#1515 closed enhancement (wontfix)

Injecting into database exceptions is more portable than copying exceptions

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


In django.core.db.init exceptions like DatabaseError are copied in from "the" database. This means only one database backend can be supported at any one time.

An alternate way to handle this is to inject a superclass into the database exceptions. sqlapi.exceptions is an example of this technique:

Change History (3)

comment:1 Changed 12 years ago by Michael Radziej <mir@…>

Component: Admin interfaceDatabase wrapper
Triage Stage: UnreviewedDesign decision needed

comment:2 Changed 12 years ago by Malcolm Tredinnick

The only thing preventing me from saying this is a really good idea is whether it's sensible Python practice. Somebody (me?!) needs to do some research about whether injecting extra base classes like this is frowned on. I suspect it won't work in general (e.g. C-wrapped classes), but I don't know.

If we can guarantee it works for all database exceptions, then it's a good idea.

comment:3 Changed 12 years ago by Malcolm Tredinnick

Resolution: wontfix
Status: newclosed

We can't use this. It is not possible to assign to __bases__ in new-style classes, every exception class should be derived from Exception and in Python 2.5, Exception became a new-style class. So the method touted in the above link won't work in 2.5.

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