Modify

Opened 14 years ago

Closed 12 years ago

Last modified 10 years ago

#6765 closed defect (fixed)

Hackergotchi doesn't work with trac 0.11.6

Reported by: Jens Langner Owned by: Ryan J Ollos
Priority: normal Component: HackergotchiPlugin
Severity: critical Keywords: database, cursor, scope, ProgrammingError, closed
Cc: Steffen Hoffmann 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 14 years ago by osimons

#6302 closed as duplicate.

comment:3 Changed 13 years ago by Ryan J Ollos

Cc: Steffen Hoffmann added; anonymous removed

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 13 years ago by wrobel@…

The same problem with trac 0.12

comment:5 Changed 12 years ago by Ryan J Ollos

Owner: changed from Noah Kantrowitz to Ryan J Ollos
Status: newassigned

comment:6 Changed 12 years ago by Ryan J Ollos

Resolution: fixed
Status: assignedclosed

(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 12 years ago by Steffen Hoffmann

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 10 years ago by Ryan J Ollos

Keywords: ProgrammingError closed added

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Ryan J Ollos.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


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

 
Note: See TracTickets for help on using tickets.