Catching Oracle Errors in Django

Posted by Dashdrum on Stack Overflow See other posts from Stack Overflow or by Dashdrum
Published on 2012-07-05T15:14:21Z Indexed on 2012/07/05 15:15 UTC
Read the original article Hit count: 293

Filed under:
|

My Django app runs on an Oracle database.

A few times a year, the database is unavailable because of a scheduled process or unplanned downtime. However, I can't see how to catch the error a give a useful message back to the requester. Instead, a 500 error is triggered, and I get an email (or hundreds) showing the exception. One example is:

  File "/opt/UDO/env/events/lib/python2.6/site-packages/django/db/backends/oracle/base.py", line 447, in _cursor
    self.connection = Database.connect(conn_string, **conn_params)

DatabaseError: ORA-01035: ORACLE only available to users with RESTRICTED SESSION privilege

I see a similar error with a different ORA number when the DB is down.

Because the exception is thrown deep within the Django libraries, and can be triggered by any of my views or the built in admin views, I don't know where any exception trapping code would go.

Any suggestions?

© Stack Overflow or respective owner

Related posts about django

Related posts about Oracle