[shared data] remove get/set_shared_data api

It was redundant with session_data and transaction_data and costly to maintain.

Closes #3938370.

authorAurelien Campeas <aurelien.campeas@logilab.fr>
changeset131e28c4fbe2
branchdefault
phasedraft
hiddenyes
parent revision#b7ddc538955b [entity/req] pass the _cw object to cw_instantiate
child revision#094816a25e6e [dbapi] retire repo.execute, which was used by the dbapi
files modified by this revision
doc/3.21.rst
repoapi.py
server/repository.py
server/session.py
server/test/unittest_repository.py
web/request.py
# HG changeset patch
# User Aurelien Campeas <aurelien.campeas@logilab.fr>
# Date 1401813425 -7200
# Tue Jun 03 18:37:05 2014 +0200
# Node ID 131e28c4fbe2f092b16447cf1a888a0aae6ffa82
# Parent b7ddc538955b23f148bf8a62e2fcdf6f8153ce7c
[shared data] remove get/set_shared_data api

It was redundant with session_data and transaction_data
and costly to maintain.

Closes #3938370.

diff --git a/doc/3.21.rst b/doc/3.21.rst
@@ -13,10 +13,13 @@
1  ---------------------
2 
3  * the user_callback api has been removed; people should use plain
4    ajax functions instead
5 
6 +* the get/set_shared_data api has been removed; people should use
7 +  transaction_data or session_data instead
8 +
9  * the `Pyro` and `Zmq-pickle` remote repository access methods have
10    been entirely removed (emerging alternatives such as rqlcontroller
11    and cwclientlib should be used instead).  Note that as a side effect,
12    "repository-only" instances (i.e. without a http component) are no
13    longer possible.  If you have any such instances, you will need to
diff --git a/repoapi.py b/repoapi.py
@@ -215,13 +215,10 @@
14 
15      system_sql = _srv_cnx_func('system_sql')
16 
17      # session data methods #####################################################
18 
19 -    get_shared_data = _srv_cnx_func('get_shared_data')
20 -    set_shared_data = _srv_cnx_func('set_shared_data')
21 -
22      @property
23      def transaction_data(self):
24          return self._cnx.transaction_data
25 
26      # meta-data accessors ######################################################
diff --git a/server/repository.py b/server/repository.py
@@ -724,34 +724,10 @@
27          """raise `BadConnectionId` if the connection is no more valid, else
28          return its latest activity timestamp.
29          """
30          return self._get_session(sessionid, setcnxset=False).timestamp
31 
32 -    @deprecated('[3.19] use session or transaction data')
33 -    def get_shared_data(self, sessionid, key, default=None, pop=False, txdata=False):
34 -        """return value associated to key in the session's data dictionary or
35 -        session's transaction's data if `txdata` is true.
36 -
37 -        If pop is True, value will be removed from the dictionary.
38 -
39 -        If key isn't defined in the dictionary, value specified by the
40 -        `default` argument will be returned.
41 -        """
42 -        session = self._get_session(sessionid, setcnxset=False)
43 -        return session.get_shared_data(key, default, pop, txdata)
44 -
45 -    @deprecated('[3.19] use session or transaction data')
46 -    def set_shared_data(self, sessionid, key, value, txdata=False):
47 -        """set value associated to `key` in shared data
48 -
49 -        if `txdata` is true, the value will be added to the repository session's
50 -        transaction's data which are cleared on commit/rollback of the current
51 -        transaction.
52 -        """
53 -        session = self._get_session(sessionid, setcnxset=False)
54 -        session.set_shared_data(key, value, txdata)
55 -
56      def commit(self, sessionid, txid=None):
57          """commit transaction for the session with the given id"""
58          self.debug('begin commit for session %s', sessionid)
59          try:
60              session = self._get_session(sessionid)
diff --git a/server/session.py b/server/session.py
@@ -545,32 +545,10 @@
61 
62      @property
63      def rql_rewriter(self):
64          return self._rewriter
65 
66 -    @_open_only
67 -    @deprecated('[3.19] use session or transaction data', stacklevel=3)
68 -    def get_shared_data(self, key, default=None, pop=False, txdata=False):
69 -        """return value associated to `key` in session data"""
70 -        if txdata:
71 -            data = self.transaction_data
72 -        else:
73 -            data = self._session_data
74 -        if pop:
75 -            return data.pop(key, default)
76 -        else:
77 -            return data.get(key, default)
78 -
79 -    @_open_only
80 -    @deprecated('[3.19] use session or transaction data', stacklevel=3)
81 -    def set_shared_data(self, key, value, txdata=False):
82 -        """set value associated to `key` in session data"""
83 -        if txdata:
84 -            self.transaction_data[key] = value
85 -        else:
86 -            self._session_data[key] = value
87 -
88      def clear(self):
89          """reset internal data"""
90          self.transaction_data = {}
91          #: ordered list of operations to be processed on commit/rollback
92          self.pending_operations = []
@@ -1264,12 +1242,10 @@
93        containing some shared data that should be cleared at the end of the
94        connection. Hooks and operations may put arbitrary data in there, and
95        this may also be used as a communication channel between the client and
96        the repository.
97 
98 -    .. automethod:: cubicweb.server.session.Session.get_shared_data
99 -    .. automethod:: cubicweb.server.session.Session.set_shared_data
100      .. automethod:: cubicweb.server.session.Session.added_in_transaction
101      .. automethod:: cubicweb.server.session.Session.deleted_in_transaction
102 
103      Connection state information:
104 
@@ -1557,32 +1533,10 @@
105      def local_perm_cache(self, value):
106          #base class assign an empty dict:-(
107          assert value == {}
108          pass
109 
110 -    # shared data handling ###################################################
111 -
112 -    @deprecated('[3.19] use session or transaction data')
113 -    def get_shared_data(self, key, default=None, pop=False, txdata=False):
114 -        """return value associated to `key` in session data"""
115 -        if txdata:
116 -            return self._cnx.get_shared_data(key, default, pop, txdata=True)
117 -        else:
118 -            data = self.data
119 -        if pop:
120 -            return data.pop(key, default)
121 -        else:
122 -            return data.get(key, default)
123 -
124 -    @deprecated('[3.19] use session or transaction data')
125 -    def set_shared_data(self, key, value, txdata=False):
126 -        """set value associated to `key` in session data"""
127 -        if txdata:
128 -            return self._cnx.set_shared_data(key, value, txdata=True)
129 -        else:
130 -            self.data[key] = value
131 -
132      # server-side service call #################################################
133 
134      call_service = cnx_meth('call_service')
135 
136      # request interface #######################################################
diff --git a/server/test/unittest_repository.py b/server/test/unittest_repository.py
@@ -169,30 +169,10 @@
137 
138      def test_invalid_cnxid(self):
139          self.assertRaises(BadConnectionId, self.repo.execute, 0, 'Any X')
140          self.assertRaises(BadConnectionId, self.repo.close, None)
141 
142 -    def test_shared_data(self):
143 -        repo = self.repo
144 -        cnxid = repo.connect(self.admlogin, password=self.admpassword)
145 -        repo.set_shared_data(cnxid, 'data', 4)
146 -        cnxid2 = repo.connect(self.admlogin, password=self.admpassword)
147 -        self.assertEqual(repo.get_shared_data(cnxid, 'data'), 4)
148 -        self.assertEqual(repo.get_shared_data(cnxid2, 'data'), None)
149 -        repo.set_shared_data(cnxid2, 'data', 5)
150 -        self.assertEqual(repo.get_shared_data(cnxid, 'data'), 4)
151 -        self.assertEqual(repo.get_shared_data(cnxid2, 'data'), 5)
152 -        repo.get_shared_data(cnxid2, 'data', pop=True)
153 -        self.assertEqual(repo.get_shared_data(cnxid, 'data'), 4)
154 -        self.assertEqual(repo.get_shared_data(cnxid2, 'data'), None)
155 -        repo.close(cnxid)
156 -        repo.close(cnxid2)
157 -        self.assertRaises(BadConnectionId, repo.get_shared_data, cnxid, 'data')
158 -        self.assertRaises(BadConnectionId, repo.get_shared_data, cnxid2, 'data')
159 -        self.assertRaises(BadConnectionId, repo.set_shared_data, cnxid, 'data', 1)
160 -        self.assertRaises(BadConnectionId, repo.set_shared_data, cnxid2, 'data', 1)
161 -
162      def test_check_session(self):
163          repo = self.repo
164          cnxid = repo.connect(self.admlogin, password=self.admpassword)
165          self.assertIsInstance(repo.check_session(cnxid), float)
166          repo.close(cnxid)
@@ -338,23 +318,10 @@
167          self.assertEqual(repo.describe(cnxid, 2), (u'CWGroup', 'system', None, 'system'))
168          repo.close(cnxid)
169          self.assertRaises(BadConnectionId, repo.user_info, cnxid)
170          self.assertRaises(BadConnectionId, repo.describe, cnxid, 1)
171 
172 -    def test_shared_data_api(self):
173 -        repo = self.repo
174 -        cnxid = repo.connect(self.admlogin, password=self.admpassword)
175 -        self.assertEqual(repo.get_shared_data(cnxid, 'data'), None)
176 -        repo.set_shared_data(cnxid, 'data', 4)
177 -        self.assertEqual(repo.get_shared_data(cnxid, 'data'), 4)
178 -        repo.get_shared_data(cnxid, 'data', pop=True)
179 -        repo.get_shared_data(cnxid, 'whatever', pop=True)
180 -        self.assertEqual(repo.get_shared_data(cnxid, 'data'), None)
181 -        repo.close(cnxid)
182 -        self.assertRaises(BadConnectionId, repo.set_shared_data, cnxid, 'data', 0)
183 -        self.assertRaises(BadConnectionId, repo.get_shared_data, cnxid, 'data')
184 -
185      def test_schema_is_relation(self):
186          with self.admin_access.repo_cnx() as cnx:
187              no_is_rset = cnx.execute('Any X WHERE NOT X is ET')
188              self.assertFalse(no_is_rset, no_is_rset.description)
189 
diff --git a/web/request.py b/web/request.py
@@ -1012,12 +1012,10 @@
190              self._ = self.__ = unicode
191              self.pgettext = lambda x, y: unicode(y)
192 
193      entity_metas = _cnx_func('entity_metas')
194      source_defs = _cnx_func('source_defs')
195 -    get_shared_data = _cnx_func('get_shared_data')
196 -    set_shared_data = _cnx_func('set_shared_data')
197      describe = _cnx_func('describe') # deprecated XXX
198 
199      # security #################################################################
200 
201      security_enabled = _cnx_func('security_enabled')