server/session.py
changeset 9684 a6b084ea4c5b
parent 9630 e7dbc4f06a48
child 9707 4a23058e4d9f
equal deleted inserted replaced
9683:74359402bfb0 9684:a6b084ea4c5b
   529         self._open = True
   529         self._open = True
   530         return self
   530         return self
   531 
   531 
   532     def __exit__(self, exctype=None, excvalue=None, tb=None):
   532     def __exit__(self, exctype=None, excvalue=None, tb=None):
   533         assert self._open # actually already open
   533         assert self._open # actually already open
       
   534         assert self._cnxset_count == 0
   534         self._free_cnxset(ignoremode=True)
   535         self._free_cnxset(ignoremode=True)
   535         self.clear()
   536         self.clear()
   536         self._open = False
   537         self._open = False
   537 
   538 
   538 
   539 
   617         """the connection is no longer using its connections set, at least for some time"""
   618         """the connection is no longer using its connections set, at least for some time"""
   618         # cnxset may be none if no operation has been done since last commit
   619         # cnxset may be none if no operation has been done since last commit
   619         # or rollback
   620         # or rollback
   620         cnxset = self.cnxset
   621         cnxset = self.cnxset
   621         if cnxset is not None and (ignoremode or self.mode == 'read'):
   622         if cnxset is not None and (ignoremode or self.mode == 'read'):
       
   623             assert self._cnxset_count == 0
   622             try:
   624             try:
   623                 self.cnxset = None
   625                 self.cnxset = None
   624             finally:
   626             finally:
   625                 cnxset.cnxset_freed()
   627                 cnxset.cnxset_freed()
   626                 self.repo._free_cnxset(cnxset)
   628                 self.repo._free_cnxset(cnxset)
  1025         """rollback the current transaction"""
  1027         """rollback the current transaction"""
  1026         if reset_pool is not None:
  1028         if reset_pool is not None:
  1027             warn('[3.13] use free_cnxset argument instead for reset_pool',
  1029             warn('[3.13] use free_cnxset argument instead for reset_pool',
  1028                  DeprecationWarning, stacklevel=2)
  1030                  DeprecationWarning, stacklevel=2)
  1029             free_cnxset = reset_pool
  1031             free_cnxset = reset_pool
       
  1032         if self._cnxset_count != 0:
       
  1033             # we are inside ensure_cnx_set, don't lose it
       
  1034             free_cnxset = False
  1030         cnxset = self.cnxset
  1035         cnxset = self.cnxset
  1031         if cnxset is None:
  1036         if cnxset is None:
  1032             self.clear()
  1037             self.clear()
  1033             self._session_timestamp.touch()
  1038             self._session_timestamp.touch()
  1034             self.debug('rollback transaction %s done (no db activity)', self.connectionid)
  1039             self.debug('rollback transaction %s done (no db activity)', self.connectionid)
  1062             assert not self.pending_operations
  1067             assert not self.pending_operations
  1063             self.clear()
  1068             self.clear()
  1064             self._session_timestamp.touch()
  1069             self._session_timestamp.touch()
  1065             self.debug('commit transaction %s done (no db activity)', self.connectionid)
  1070             self.debug('commit transaction %s done (no db activity)', self.connectionid)
  1066             return
  1071             return
       
  1072         if self._cnxset_count != 0:
       
  1073             # we are inside ensure_cnx_set, don't lose it
       
  1074             free_cnxset = False
  1067         cstate = self.commit_state
  1075         cstate = self.commit_state
  1068         if cstate == 'uncommitable':
  1076         if cstate == 'uncommitable':
  1069             raise QueryError('transaction must be rolled back')
  1077             raise QueryError('transaction must be rolled back')
  1070         if cstate is not None:
  1078         if cstate is not None:
  1071             return
  1079             return