Ticket #7262 (closed defect: fixed)

Opened 3 years ago

Last modified 1 month ago

db.close() should not be used in trac 0.12

Reported by: ejucovy Assigned to: k0s
Priority: normal Component: TracSqlHelperScript
Severity: normal Keywords:
Cc: Trac Release: 0.12

Description (Last modified by rjollos)

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, comment:4:ticket:7182-- though I don't know if it will cause additional problems.

Attachments

connection.diff (0.7 kB) - added by ejucovy on 06/18/10 16:38:48.
Attaching patch

Change History

06/18/10 16:34:41 changed by ejucovy

I can branch sqlhelperscript for 0.12-compat and commit this patch if you give me access -- I don't seem to have write access on this plugin at trac-hacks. Thanks!

06/18/10 16:38:48 changed by ejucovy

  • attachment connection.diff added.

Attaching patch

06/24/10 20:34:27 changed by anonymous

  • status changed from new to closed.
  • resolution set to fixed.

branched for 0.12 compatibility and committed patch on that branch - r8157, r8158, r8159

-ejucovy

04/19/13 16:44:38 changed by rjollos

(In [12978]) Refs #7262: Renamed anyrelease directory to 0.11.

04/19/13 17:36:56 changed by rjollos

  • description changed.

I'm not sure that [12978] was a good idea, but on the other hand, I don't think it's a good idea to retain a directory named anyrelease, when it no longer works with any release. I've tested that the TracHoursPlugin installs correctly in Trac 0.11 from trachoursplugin/branches/0.11, and I'll do the same for other plugins that utilize the TracSqlHelperScript, after changing their setup script to point to 0.11 rather than anyrelease.

04/19/13 18:04:45 changed by rjollos

(In [12983]) Refs #7262: Bump version of 0.12 branch, so that it differs from the 0.11 branch following [8159].

04/19/13 18:25:13 changed by rjollos

The setup.pys for the following projects point to tracsqlhelperscript/anyrelease, and will need to be modified to point to tracsqlhelperscript/0.11:

04/19/13 18:30:52 changed by rjollos

(In [12984]) Refs #7262: Point setup,py link to TracSqlHelperScript 0.11 directory rather than anyrelease directory.


Add/Change #7262 (db.close() should not be used in trac 0.12)




Change Properties
Action