Cannot catch _mysql_exceptions.OperationalError
nagle at animats.com
Fri Jan 18 08:03:18 CET 2008
> In our database code (we are using django v0.96) we wanted to catch
> and handle MySQL OperationalErrors. We use both the Django models and
> database connections.
> However, even though we confirmed that a
> _mysql_exceptions.OperationalError are raised (particularly 1213
> deadlock), we cannot catch them with try/except.
If you're using MySQLdb, it works fine:
... do database operations
except MySQLdb.OperationalError, message: # handle trouble
errorcode = message # get MySQL error code
if errorcode == kmysqlduplicateentry : # if dup on insert
... deal with duplicate entry
If Django has a problem, you'll have to take that up with them.
More information about the Python-list