Commit 6a613e20 authored by Pierre-Yves David's avatar Pierre-Yves David
Browse files

rename server.session.transaction into server.session.connection

The ongoing rework of the API to access the database include the splitting of
Session in two objects:

The ``Session`` object will only hold credential (user) and global session data.
A new object will publicly emerge to handle a database access. This object is
named ``Connection`` since that the way database accessors with the same property
are named in other system. So we renamed the ``Transaction`` object into
``Connection``. The ``Transaction`` object have already grown in the direction
of something directly usable by generic code, but the name ``Transaction`` is
ill suited as such object can be used for multiple database transaction in a
row.

Related to #2503918
parent e08f9c55dab5
......@@ -262,8 +262,8 @@ class BaseQuerierTC(TestCase):
u = self.repo._build_user(self.session, self.session.user.eid)
u._groups = set(groups)
s = Session(u, self.repo)
s._tx.cnxset = self.cnxset
s._tx.ctx_count = 1
s._cnx.cnxset = self.cnxset
s._cnx.ctx_count = 1
# register session to ensure it gets closed
self._dumb_sessions.append(s)
return s
......@@ -311,8 +311,8 @@ class BasePlannerTC(BaseQuerierTC):
del self.repo.sources_by_uri[source.uri]
undo_monkey_patch()
for session in self._dumb_sessions:
if session._tx.cnxset is not None:
session._tx.cnxset = None
if session._cnx.cnxset is not None:
session._cnx.cnxset = None
session.close()
def _prepare_plan(self, rql, kwargs=None):
......
......@@ -855,7 +855,7 @@ class Repository(object):
self.debug('begin commit for session %s', sessionid)
try:
session = self._get_session(sessionid)
session.set_tx(txid)
session.set_cnx(txid)
return session.commit()
except (ValidationError, Unauthorized):
raise
......@@ -868,7 +868,7 @@ class Repository(object):
self.debug('begin rollback for session %s', sessionid)
try:
session = self._get_session(sessionid)
session.set_tx(txid)
session.set_cnx(txid)
session.rollback()
except Exception:
self.exception('unexpected error')
......@@ -1027,7 +1027,7 @@ class Repository(object):
except KeyError:
raise BadConnectionId('No such session %s' % sessionid)
if setcnxset:
session.set_tx(txid) # must be done before set_cnxset
session.set_cnx(txid) # must be done before set_cnxset
session.set_cnxset()
return session
......
This diff is collapsed.
......@@ -33,7 +33,7 @@ class SessionTC(CubicWebTC):
self.assertEqual(HOOKS_ALLOW_ALL, session.hooks_mode)
self.assertEqual(set(), session.disabled_hook_categories)
self.assertEqual(set(), session.enabled_hook_categories)
self.assertEqual(1, len(session._txs))
self.assertEqual(1, len(session._cnxs))
with session.deny_all_hooks_but('metadata'):
self.assertEqual(HOOKS_DENY_ALL, session.hooks_mode)
self.assertEqual(set(), session.disabled_hook_categories)
......@@ -55,7 +55,7 @@ class SessionTC(CubicWebTC):
self.assertEqual(set(('metadata',)), session.enabled_hook_categories)
# leaving context manager with no transaction running should reset the
# transaction local storage (and associated cnxset)
self.assertEqual({}, session._txs)
self.assertEqual({}, session._cnxs)
self.assertEqual(None, session.cnxset)
self.assertEqual(HOOKS_ALLOW_ALL, session.hooks_mode, session.HOOKS_ALLOW_ALL)
self.assertEqual(set(), session.disabled_hook_categories)
......
......@@ -20,7 +20,7 @@
from cubicweb import ValidationError
from cubicweb.devtools.testlib import CubicWebTC
import cubicweb.server.session
from cubicweb.server.session import Transaction as OldTransaction
from cubicweb.server.session import Connection as OldConnection
from cubicweb.transaction import *
from cubicweb.server.sources.native import UndoTransactionException, _UndoException
......@@ -35,14 +35,14 @@ class UndoableTransactionTC(CubicWebTC):
self.txuuid = self.commit()
def setUp(self):
class Transaction(OldTransaction):
class Connection(OldConnection):
"""Force undo feature to be turned on in all case"""
undo_actions = property(lambda tx: True, lambda x, y:None)
cubicweb.server.session.Transaction = Transaction
cubicweb.server.session.Connection = Connection
super(UndoableTransactionTC, self).setUp()
def tearDown(self):
cubicweb.server.session.Transaction = OldTransaction
cubicweb.server.session.Connection = OldConnection
self.restore_connection()
self.session.undo_support = set()
super(UndoableTransactionTC, self).tearDown()
......
......@@ -33,7 +33,7 @@ from cubicweb.utils import json_dumps
from cubicweb.uilib import rql_for_eid
from cubicweb.web import INTERNAL_FIELD_VALUE, Redirect, RequestError, RemoteCallFailed
import cubicweb.server.session
from cubicweb.server.session import Transaction as OldTransaction
from cubicweb.server.session import Connection as OldConnection
from cubicweb.entities.authobjs import CWUser
from cubicweb.web.views.autoform import get_pending_inserts, get_pending_deletes
from cubicweb.web.views.basecontrollers import JSonController, xhtmlize, jsonize
......@@ -762,15 +762,15 @@ class JSonControllerTC(AjaxControllerTC):
class UndoControllerTC(CubicWebTC):
def setUp(self):
class Transaction(OldTransaction):
class Connection(OldConnection):
"""Force undo feature to be turned on in all case"""
undo_actions = property(lambda tx: True, lambda x, y:None)
cubicweb.server.session.Transaction = Transaction
cubicweb.server.session.Connection = Connection
super(UndoControllerTC, self).setUp()
def tearDown(self):
super(UndoControllerTC, self).tearDown()
cubicweb.server.session.Transaction = OldTransaction
cubicweb.server.session.Connection = OldConnection
def setup_database(self):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment