Ticket #6765 (closed defect: fixed)

Opened 3 years ago

Last modified 1 year ago

Hackergotchi doesn't work with trac 0.11.6

Reported by: Jens.Langner@light-speed.de Assigned to: rjollos
Priority: normal Component: HackergotchiPlugin
Severity: critical Keywords: database cursor scope
Cc: hasienda Trac Release: 0.11

Description

After trying to install the HackergotchiPlugin in a trac 0.11.6 installation I get the following error:

ProgrammingError: Cannot operate on a closed cursor.

After some investigation and help from #trac I found the following code in Hackergotchi to be responsible for the error. Here is a patch for it:

Index: hackergotchi/web_ui.py
===================================================================
--- hackergotchi/web_ui.py	(revision 7751)
+++ hackergotchi/web_ui.py	(working copy)
@@ -29,8 +29,6 @@
     def filter_stream(self, req, method, filename, stream, data):
         if req.path_info.startswith('/timeline'):
             closure_state = [0]
-            db = self.env.get_db_cnx()
-            cursor = db.cursor()
             cache = {}
             def f(stream):
                 # Update the closed value
@@ -43,6 +41,8 @@
                 if user_info is not None:
                     author, name, email = user_info
                 else:
+                    db = self.env.get_db_cnx()
+                    cursor = db.cursor()
                     user_info = self._get_info(author, cursor)
                     cache[author] = user_info
                     author, name, email = user_info

After applying that patch the error disappeared.

Attachments

Change History

03/04/10 12:01:38 changed by osimons

03/04/10 12:23:49 changed by osimons

#6302 closed as duplicate.

12/08/10 08:59:02 changed by rjollos

  • cc set to hasienda.

I've been trying to understand this issue by studying various cases where it appears (and it appears quite frequently!). Is it possible that the db object could still be garbage collected with this patch? What about the following alternative patch?

  • 0.11/hackergotchi/web_ui.py

    old new  
    2929    def filter_stream(self, req, method, filename, stream, data): 
    3030        if req.path_info.startswith('/timeline'): 
    3131            closure_state = [0] 
    32             db = self.env.get_db_cnx() 
    33             cursor = db.cursor() 
    3432            cache = {} 
    3533            def f(stream): 
    3634                # Update the closed value 
     
    4341                if user_info is not None: 
    4442                    author, name, email = user_info 
    4543                else: 
    46                     user_info = self._get_info(author, cursor) 
     44                    db = self.env.get_db_cnx() 
     45                    user_info = self._get_info(author, db) 
    4746                    cache[author] = user_info 
    4847                    author, name, email = user_info 
    4948                 
     
    7574        return [] 
    7675     
    7776    # Internal methods 
    78     def _get_info(self, author, cursor): 
     77    def _get_info(self, author, db): 
     78        cursor = db.cursor() 
    7979        if author == 'anonymous': 
    8080            # Don't even bother trying for "anonymous" 
    8181            return author, None, None 

10/20/11 09:27:58 changed by wrobel@wsb-nlu.edu.pl

The same problem with trac 0.12

02/05/12 09:04:05 changed by rjollos

  • owner changed from coderanger to rjollos.
  • status changed from new to assigned.

(follow-up: ↓ 7 ) 02/05/12 10:25:08 changed by rjollos

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

(In [11248]) Fixes #6765: Attempt to fix "Cannot operate on a closed cursor." error by passing the db object rather than the cursor object to the subfunction. The assumption here is that the db object is going out of scope.

I wasn't able to reproduce the issue with Trac 0.11 in a development environment. Please report back if this fixes the issue for you.

(in reply to: ↑ 6 ) 02/05/12 15:07:02 changed by hasienda

  • keywords set to database cursor scope.

Replying to rjollos:

(In [11248]) Fixes #6765: Attempt to fix "Cannot operate on a closed cursor." error by passing the db object rather than the cursor object to the subfunction. The assumption here is that the db object is going out of scope.

Sure, very reasonable IMHO. I've been looking for this kind of issue too after I got bitten by such a similar issue. Cursors should never be passed to methods/functions - another thing for our upcoming best-practice documentation.


Add/Change #6765 (Hackergotchi doesn't work with trac 0.11.6)




Change Properties
Action