my db query returns an InternalError, I tried to check for this error using isinstance and comparing it to the import of pymysql.err import InternalError, but this comparison fails for some reason. What am I doing wrong here?
from pymysql.err import InternalError
result = execute_sql("bad insert query")
if isinstance(result, InternalError):
return "Insert has failed"
def execute_sql(sql_query):
try:
session.execute(sql_query)
except Exception as db_error:
log(query) # log the query that caused the error
return db_error # delegate error handling to the caller
I checked with my debugger and the result is in fact of this type. Is my import wrong, or is the comparison faulty? This should be an instance of this class, right?
# result ->
(pymysql.err.InternalError)
# import ->
<class 'pymysql.err.InternalError'>
I can also import InternalError from pymysql directly (not using .err in the import), but I already tried this and it also doesnt result in a correct check. I also tried comparing with type(result) == type(InternalError), this doesnt work either