I am using Python/Bottle/SqlAlchemy/MySQL for a web service.
I am trying to catch an IntegrityError raised by calling a stored procedure but I am unable to do that.
Using this
cursor = connection.cursor()
cursor.callproc('my_stored_proc', [arguments])
yields the same result as
try:
cursor = connection.cursor()
cursor.callproc('my_stored_proc', [arguments])
except IntegrityError as e:
print("Error: {}".format(e))
return {"message": e.message}
I get an IntegrityError exception in both cases. Why is the exception not caught in the latter case?
IntegrityErrorwill likely be raised when your transaction gets committed, not when calling the stored procedure.