db.close() should not be used in trac 0.12
|Reported by:||ejucovy||Owned by:||Jeff Hammel|
Description (last modified by )
Don't close the db connection after each SQL command is executed. In Trac 0.12 this causes subsequent db queries to have no connection, causing AttributeErrors.
29 29 Exception:%s""" %(sql, params, e)) 30 30 db.rollback() 31 31 raise 32 try: 33 db.close() 34 except: 35 pass 32 try: 33 db.close() 34 except: 35 pass 36 36 return self.return_values(**_data)
AFAICT this is a band-aid over a bigger issue. SQLHelperScript does not distinguish between commands that write to the db and commands that only read from it -- all commands will commit and roll-back the database. It also tries to manage its own database connections (get_db_cnx and the now-commented-out db.close()). And in fact it seems like as of Trac 0.12 it should not be trying to manage its own transactions either, or if it does it should be using the with_transaction decorator. But my hunch is that none of this should be managed at the level of the individual SQL command objects, rather by their callers.
Regardless this small change seems to fix the immediate issue, comment:4:ticket:7182-- though I don't know if it will cause additional problems.