Opened 4 years ago

Closed 4 years ago

Last modified 3 years 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:


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/", line 233, in dispatch
  File "/home/user/Workspace/th11043/trac-0.11/trac/web/", line 301, in _post_process_request
    f.post_process_request(req, *(None,)*extra_arg_count)
  File "/home/user/Workspace/trachacks.git/bookmarkplugin/trunk/tracbookmark/", line 183, in post_process_request
  File "/home/user/Workspace/trachacks.git/bookmarkplugin/trunk/tracbookmark/", line 335, in render_bookmarker
    menu = self._get_bookmarks_menu(req)
  File "/home/user/Workspace/trachacks.git/bookmarkplugin/trunk/tracbookmark/", 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/", 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 4 years ago by jun66j5

Indeed. We must keep the db variable while in use of cursor. See!msg/trac-dev/trRtzv5waoQ/Uz1T1sBhTR8J and

  • tracbookmark/

    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
    6667    def get_bookmark(self, req, resource):
    6768        """Return the current users bookmark for a resource."""

comment:2 Changed 4 years 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 4 years 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 3 years ago by rjollos

  • Cc rjollos added
  • Keywords ProgrammingError closed cursor added

Add Comment

Modify Ticket

as closed The owner will remain rjollos.
The resolution will be deleted. Next status will be 'reopened'.

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

Note: See TracTickets for help on using tickets.