38 from logilab.common.decorators import cached, classproperty, clear_cache, iclassmethod |
38 from logilab.common.decorators import cached, classproperty, clear_cache, iclassmethod |
39 from logilab.common.deprecation import deprecated, class_deprecated |
39 from logilab.common.deprecation import deprecated, class_deprecated |
40 from logilab.common.shellutils import getlogin |
40 from logilab.common.shellutils import getlogin |
41 |
41 |
42 from cubicweb import (ValidationError, NoSelectableObject, AuthenticationError, |
42 from cubicweb import (ValidationError, NoSelectableObject, AuthenticationError, |
43 ProgrammingError) |
43 ProgrammingError, BadConnectionId) |
44 from cubicweb import cwconfig, devtools, web, server, repoapi |
44 from cubicweb import cwconfig, devtools, web, server, repoapi |
45 from cubicweb.utils import json |
45 from cubicweb.utils import json |
46 from cubicweb.sobjects import notification |
46 from cubicweb.sobjects import notification |
47 from cubicweb.web import Redirect, application |
47 from cubicweb.web import Redirect, application |
48 from cubicweb.server.hook import SendMailOp |
48 from cubicweb.server.hook import SendMailOp |
295 self._open_access.add(access) |
295 self._open_access.add(access) |
296 return access |
296 return access |
297 |
297 |
298 def _close_access(self): |
298 def _close_access(self): |
299 while self._open_access: |
299 while self._open_access: |
300 self._open_access.pop().close() |
300 try: |
|
301 self._open_access.pop().close() |
|
302 except BadConnectionId: |
|
303 continue # already closed |
301 |
304 |
302 @deprecated('[3.19] explicitly use RepoAccess object in test instead') |
305 @deprecated('[3.19] explicitly use RepoAccess object in test instead') |
303 def set_cnx(self, cnx): |
306 def set_cnx(self, cnx): |
304 assert getattr(cnx, '_session', None) is not None |
307 assert getattr(cnx, '_session', None) is not None |
305 if cnx is self._admin_clt_cnx: |
308 if cnx is self._admin_clt_cnx: |
550 self._init_repo() |
553 self._init_repo() |
551 self.addCleanup(self._close_cnx) |
554 self.addCleanup(self._close_cnx) |
552 except Exception as ex: |
555 except Exception as ex: |
553 self.__class__._repo_init_failed = ex |
556 self.__class__._repo_init_failed = ex |
554 raise |
557 raise |
|
558 self.addCleanup(self._close_access) |
555 resume_tracing() |
559 resume_tracing() |
556 self.setup_database() |
560 self.setup_database() |
557 self._admin_clt_cnx.commit() |
561 self._admin_clt_cnx.commit() |
558 MAILBOX[:] = [] # reset mailbox |
562 MAILBOX[:] = [] # reset mailbox |
559 |
563 |