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
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to