Opened 14 years ago
Last modified 11 years ago
#7262 closed defect
db.close() should not be used in trac 0.12 — at Initial Version
Reported by: | ejucovy | Owned by: | Jeff Hammel |
---|---|---|---|
Priority: | normal | Component: | TracSqlHelperScript |
Severity: | normal | Keywords: | |
Cc: | Trac Release: | 0.12 |
Description
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.
Patch:
Index: tracsqlhelper/__init__.py =================================================================== --- tracsqlhelper/__init__.py (revision 8119) +++ tracsqlhelper/__init__.py (working copy) @@ -29,10 +29,10 @@ Exception:%s""" %(sql, params, e)) db.rollback() raise - try: - db.close() - except: - pass + #try: + # db.close() + #except: + # pass 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, http://trac-hacks.org/ticket/7182#comment:4 -- though I don't know if it will cause additional problems.