Cannot catch _mysql_exceptions.OperationalError
John Nagle
nagle at animats.com
Fri Jan 18 02:03:18 EST 2008
Bob wrote:
> 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:
try:
... do database operations
except MySQLdb.OperationalError, message: # handle trouble
errorcode = message[0] # 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.
John Nagle
More information about the Python-list
mailing list