I experienced trouble where with SQLObject, if something you do raises a
MySQL error (such as a duplicate key on insertion), SQLObject does not
ever free the database connection used when that error was raised.
Eventually this will lead to a "too many connections" error from MySQLdb.
I searched google for SQLObject and "too many connections" (the error
you'll eventually get) and it didn't turn up anything so I assume I'm the
first one to get this error.
Upon exploring the source code, I think I have isolated the problem. Your
DBAPI.runWithConnection method from SQLObject/DBConnection.py has the
following definition:
def _runWithConnection(self, meth, *args):
conn = self.getConnection()
val = meth(conn, *args)
self.releaseConnection(conn)
return val
In the event that meth(...) raises an error, releaseConnection is never
called. To allow the exception to be raised like it is now but the
database connection released regardless, I suggest:
def _runWithConnection(self, meth, *args):
conn = self.getConnection()
try:
val = meth(conn, *args)
finally:
self.releaseConnection(conn)
return val
I've attached a patch which applies the above change. Do with it as you may.
Thanks
Ken
|