Opened 5 years ago

Closed 5 years ago

Last modified 4 years ago

#11115 closed defect (fixed)

Cannot operate on closed cursor

Reported by: Ryan J Ollos Owned by: Ryan J Ollos
Priority: normal Component: BookmarkPlugin
Severity: normal Keywords: ProgrammingError, closed, cursor
Cc: Jun Omae, Ryan J Ollos 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 5 years ago by Jun Omae

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

Owner: changed from yosiyuki to Ryan J Ollos
Status: newassigned

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

comment:3 Changed 5 years ago by Ryan J Ollos

Resolution: fixed
Status: assignedclosed

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

comment:4 Changed 4 years ago by Ryan J Ollos

Cc: Ryan J Ollos added
Keywords: ProgrammingError closed cursor added

Modify Ticket

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

Add Comment

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

Note: See TracTickets for help on using tickets.