Modify

Opened 4 years ago

Closed 2 years ago

Last modified 2 months ago

#6765 closed defect (fixed)

Hackergotchi doesn't work with trac 0.11.6

Reported by: Jens.Langner@… Owned by: rjollos
Priority: normal Component: HackergotchiPlugin
Severity: critical Keywords: database, cursor, scope, ProgrammingError, closed
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 (0)

Change History (8)

comment:2 Changed 4 years ago by osimons

#6302 closed as duplicate.

comment:3 Changed 3 years ago by rjollos

  • Cc hasienda added

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

     
    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 

comment:4 Changed 3 years ago by wrobel@…

The same problem with trac 0.12

comment:5 Changed 2 years ago by rjollos

  • Owner changed from coderanger to rjollos
  • Status changed from new to assigned

comment:6 follow-up: Changed 2 years ago by rjollos

  • Resolution set to fixed
  • Status changed from assigned to closed

(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.

comment:7 in reply to: ↑ 6 Changed 2 years ago by hasienda

  • Keywords database cursor scope added

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.

comment:8 Changed 2 months ago by rjollos

  • Keywords ProgrammingError closed added

Add Comment

Modify Ticket

Action
as closed .
as The resolution will be set. Next status will be 'closed'.
to The owner will be changed from rjollos. Next status will be 'closed'.
The resolution will be deleted. Next status will be 'reopened'.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.