Edgewall Software

Ticket #9104: t9104-fix-operate-closed-cursor-r9282.diff

File t9104-fix-operate-closed-cursor-r9282.diff, 1.9 KB (added by cboos, 2 years ago)

web: avoid using a cursor after the connection from which it depends has been rollbacked

  • trac/web/session.py

    # HG changeset patch
    # Parent 2fd35685f8d81b1cf7bfa69f44f10e212c88562e
    web: avoid using a cursor after the connection from which it depends has been rollbacked (as this doesn't work with PySqlite due to some explicit close on rollback we do).
    
    Closes #9104.
    
    diff --git a/trac/web/session.py b/trac/web/session.py
    a b class DetachedSession(dict): 
    7979        authenticated = int(self.authenticated) 
    8080        now = int(time.time()) 
    8181        db = self.env.get_db_cnx() 
    82         cursor = db.cursor() 
    8382 
    8483        if self._new: 
    8584            self.last_visit = now 
    class DetachedSession(dict): 
    8786            # The session might already exist even if _new is True since 
    8887            # it could have been created by a concurrent request (#3563). 
    8988            try: 
     89                cursor = db.cursor() 
    9090                cursor.execute("INSERT INTO session (sid,last_visit,authenticated)" 
    9191                               " VALUES(%s,%s,%s)", 
    9292                               (self.sid, self.last_visit, authenticated)) 
    class DetachedSession(dict): 
    9696                                     (self.sid, e)) 
    9797        if self._old != self: 
    9898            attrs = [(self.sid, authenticated, k, v) for k, v in self.items()] 
     99            cursor = db.cursor() 
    99100            cursor.execute("DELETE FROM session_attribute WHERE sid=%s", 
    100101                           (self.sid,)) 
    101102            self._old = dict(self.items()) 
    class DetachedSession(dict): 
    122123        if now - self.last_visit > UPDATE_INTERVAL: 
    123124            self.last_visit = now 
    124125            self.env.log.info("Refreshing session %s" % self.sid) 
     126            cursor = db.cursor() 
    125127            cursor.execute('UPDATE session SET last_visit=%s ' 
    126128                           'WHERE sid=%s AND authenticated=%s', 
    127129                           (self.last_visit, self.sid, authenticated))