Modify

Opened 16 months ago

Closed 16 months ago

Last modified 7 months ago

#11115 closed defect (fixed)

Cannot operate on closed cursor

Reported by: rjollos Owned by: rjollos
Priority: normal Component: BookmarkPlugin
Severity: normal Keywords: ProgrammingError, closed, cursor
Cc: jun66j5, rjollos Trac Release:

Description

While testing with Trac 0.11, I've seen the following in the logs:

11:17:19 AM Trac[main] ERROR: Cannot operate on a closed cursor.
Traceback (most recent call last):
  File "/home/user/Workspace/th11043/trac-0.11/trac/web/main.py", line 233, in dispatch
    self._post_process_request(req)
  File "/home/user/Workspace/th11043/trac-0.11/trac/web/main.py", line 301, in _post_process_request
    f.post_process_request(req, *(None,)*extra_arg_count)
  File "/home/user/Workspace/trachacks.git/bookmarkplugin/trunk/tracbookmark/__init__.py", line 183, in post_process_request
    self.render_bookmarker(req)
  File "/home/user/Workspace/trachacks.git/bookmarkplugin/trunk/tracbookmark/__init__.py", line 335, in render_bookmarker
    menu = self._get_bookmarks_menu(req)
  File "/home/user/Workspace/trachacks.git/bookmarkplugin/trunk/tracbookmark/__init__.py", line 342, in _get_bookmarks_menu
    for url, name, username in self.get_bookmarks(req):
  File "/home/user/Workspace/th11043/trac-0.11/trac/db/util.py", line 40, in __iter__
    row = self.cursor.fetchone()
ProgrammingError: Cannot operate on a closed cursor.

The error occurs when loading any page, such as WikiStart. I think we shouldn't be returning a cursor from get_bookmarks.

Attachments (0)

Change History (4)

comment:1 Changed 16 months ago by jun66j5

Indeed. We must keep the db variable while in use of cursor. See https://groups.google.com/forum/?fromgroups#!msg/trac-dev/trRtzv5waoQ/Uz1T1sBhTR8J and http://trac.edgewall.org/changeset/8878.

  • tracbookmark/__init__.py

     
    6161        cursor.execute( 
    6262            "SELECT resource, name, username FROM bookmarks WHERE username=%s", 
    6363            (get_reporter_id(req),)) 
    64         return cursor 
     64        for row in cursor: 
     65            yield row 
    6566 
    6667    def get_bookmark(self, req, resource): 
    6768        """Return the current users bookmark for a resource.""" 

comment:2 Changed 16 months ago by rjollos

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

Thanks! Initially I had just called fetchall on the cursor, but returning an iterator is probably better.

comment:3 Changed 16 months ago by rjollos

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

(In [13227]) Fixes #11115: Avoid Cannot operate on closed cursor errors by not returning a cursor from a function.

comment:4 Changed 7 months ago by rjollos

  • Cc changed from jun66j5,rjollos to jun66j5, rjollos
  • Keywords ProgrammingError closed cursor added

Add Comment

Modify Ticket

Action
as 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.