Hi,
I have an application that uses twisted.enterprise.adbapi for accessing sqlite database. Recently I had to replace sqlite3 shipped with python 2.5 with latest version of pysqlite2. This was for taking advantage of newer fixes in pysqlite2. I thought it would be worthwhile to support both.
However, functions called using runInteraction have a code block as given below. try: txn.execute(“update query”) except sqlite3.IntegrityError: handleDuplicateValues()
or an errback on the function runQuery/Interaction/Operation. They all used twisted.python.failure.check/trap on some exception of the form sqlite3.some_dbapi_exception. Now, all such places need to import exceptions from pysqlite2 instead of sqlite3.
However, to handle multiple dbapi modules one of which will be configured for use by the user, I thought, I will have a global name having reference of the current dbapi module being used. This will be used by errbacks and except blocks.
Is there a better way of handling exceptions in such cases?
I came across http://svn.sqlalchemy.org/sqlalchemy/trunk/lib/sqlalchemy/exc.py. I think sqlalchemy wraps dbapi erros in DBAPIError exception. I imagine doing something similar in twisted as, try: txn.execute(“update query”) except adbapi.IntegrityError: handleDuplicateValues()
I also came across http://mail.python.org/pipermail/db-sig/2003-September/003686.html which suggests exceptions raised by different modules for same type of error may not be consistent, atleast with respect to the information provided.
Any suggestions on this would be very helpful.
Just to note http://twistedsphinx.funsize.net/projects/core/howto/rdbms.html does not have error handling related info.