[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>
changeset06dba6d6b5e6
branchdefault
phasedraft
hiddenyes
parent revision#11d90290217f [entity/req] pass the _cw object to cw_instantiate
child revision#5e3eff0e5c5f [views,js] remove user_callback feature
files modified by this revision
dbapi.py
doc/3.21.rst
repoapi.py
server/repository.py
server/session.py
server/test/unittest_repository.py
test/unittest_dbapi.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 06dba6d6b5e63e30b912abf075fdbce7490a2d58
# Parent 11d90290217fdea899e39a8fb7fd8e289aaf7843
[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/dbapi.py b/dbapi.py
@@ -339,26 +339,10 @@
1          if eid is None:
2              self._eid_cache = {}
3          else:
4              del self._eid_cache[eid]
5 
6 -    # low level session data management #######################################
7 -
8 -    @deprecated('[3.19] use session or transaction data')
9 -    def get_shared_data(self, key, default=None, pop=False, txdata=False):
10 -        """see :meth:`Connection.get_shared_data`"""
11 -        return self.cnx.get_shared_data(key, default, pop, txdata)
12 -
13 -    @deprecated('[3.19] use session or transaction data')
14 -    def set_shared_data(self, key, value, txdata=False, querydata=None):
15 -        """see :meth:`Connection.set_shared_data`"""
16 -        if querydata is not None:
17 -            txdata = querydata
18 -            warn('[3.10] querydata argument has been renamed to txdata',
19 -                 DeprecationWarning, stacklevel=2)
20 -        return self.cnx.set_shared_data(key, value, txdata)
21 -
22      # server session compat layer #############################################
23 
24      def entity_metas(self, eid):
25          """return a tuple (type, sourceuri, extid) for the entity with id <eid>"""
26          return self.cnx.entity_metas(eid)
@@ -623,34 +607,10 @@
27      def _txid(self, cursor=None): # pylint: disable=E0202
28          # XXX could now handle various isolation level!
29          # return a dict as bw compat trick
30          return {'txid': currentThread().getName()}
31 
32 -    # session data methods #####################################################
33 -
34 -    @check_not_closed
35 -    def get_shared_data(self, key, default=None, pop=False, txdata=False):
36 -        """return value associated to key in the session's data dictionary or
37 -        session's transaction's data if `txdata` is true.
38 -
39 -        If pop is True, value will be removed from the dictionary.
40 -
41 -        If key isn't defined in the dictionary, value specified by the
42 -        `default` argument will be returned.
43 -        """
44 -        return self._repo.get_shared_data(self.sessionid, key, default, pop, txdata)
45 -
46 -    @check_not_closed
47 -    def set_shared_data(self, key, value, txdata=False):
48 -        """set value associated to `key` in shared data
49 -
50 -        if `txdata` is true, the value will be added to the repository
51 -        session's query data which are cleared on commit/rollback of the current
52 -        transaction.
53 -        """
54 -        return self._repo.set_shared_data(self.sessionid, key, value, txdata)
55 -
56      # meta-data accessors ######################################################
57 
58      @check_not_closed
59      def source_defs(self):
60          """Return the definition of sources used by the repository."""
diff --git a/doc/3.21.rst b/doc/3.21.rst
@@ -0,0 +1,11 @@
61 +What's new in CubicWeb 3.21?
62 +============================
63 +
64 +
65 +Deprecated code drops
66 +---------------------
67 +
68 +* the get/set_shared_data api has been removed; people should use
69 +  transaction_data or session_data instead
70 +
71 +
diff --git a/repoapi.py b/repoapi.py
@@ -238,13 +238,10 @@
72 
73      system_sql = _srv_cnx_func('system_sql')
74 
75      # session data methods #####################################################
76 
77 -    get_shared_data = _srv_cnx_func('get_shared_data')
78 -    set_shared_data = _srv_cnx_func('set_shared_data')
79 -
80      @property
81      def transaction_data(self):
82          return self._cnx.transaction_data
83 
84      # meta-data accessors ######################################################
diff --git a/server/repository.py b/server/repository.py
@@ -748,34 +748,10 @@
85          """raise `BadConnectionId` if the connection is no more valid, else
86          return its latest activity timestamp.
87          """
88          return self._get_session(sessionid, setcnxset=False).timestamp
89 
90 -    @deprecated('[3.19] use session or transaction data')
91 -    def get_shared_data(self, sessionid, key, default=None, pop=False, txdata=False):
92 -        """return value associated to key in the session's data dictionary or
93 -        session's transaction's data if `txdata` is true.
94 -
95 -        If pop is True, value will be removed from the dictionary.
96 -
97 -        If key isn't defined in the dictionary, value specified by the
98 -        `default` argument will be returned.
99 -        """
100 -        session = self._get_session(sessionid, setcnxset=False)
101 -        return session.get_shared_data(key, default, pop, txdata)
102 -
103 -    @deprecated('[3.19] use session or transaction data')
104 -    def set_shared_data(self, sessionid, key, value, txdata=False):
105 -        """set value associated to `key` in shared data
106 -
107 -        if `txdata` is true, the value will be added to the repository session's
108 -        transaction's data which are cleared on commit/rollback of the current
109 -        transaction.
110 -        """
111 -        session = self._get_session(sessionid, setcnxset=False)
112 -        session.set_shared_data(key, value, txdata)
113 -
114      def commit(self, sessionid, txid=None):
115          """commit transaction for the session with the given id"""
116          self.debug('begin commit for session %s', sessionid)
117          try:
118              session = self._get_session(sessionid)
diff --git a/server/session.py b/server/session.py
@@ -545,32 +545,10 @@
119 
120      @property
121      def rql_rewriter(self):
122          return self._rewriter
123 
124 -    @_open_only
125 -    @deprecated('[3.19] use session or transaction data')
126 -    def get_shared_data(self, key, default=None, pop=False, txdata=False):
127 -        """return value associated to `key` in session data"""
128 -        if txdata:
129 -            data = self.transaction_data
130 -        else:
131 -            data = self._session_data
132 -        if pop:
133 -            return data.pop(key, default)
134 -        else:
135 -            return data.get(key, default)
136 -
137 -    @_open_only
138 -    @deprecated('[3.19] use session or transaction data')
139 -    def set_shared_data(self, key, value, txdata=False):
140 -        """set value associated to `key` in session data"""
141 -        if txdata:
142 -            self.transaction_data[key] = value
143 -        else:
144 -            self._session_data[key] = value
145 -
146      def clear(self):
147          """reset internal data"""
148          self.transaction_data = {}
149          #: ordered list of operations to be processed on commit/rollback
150          self.pending_operations = []
@@ -1264,12 +1242,10 @@
151        containing some shared data that should be cleared at the end of the
152        connection. Hooks and operations may put arbitrary data in there, and
153        this may also be used as a communication channel between the client and
154        the repository.
155 
156 -    .. automethod:: cubicweb.server.session.Session.get_shared_data
157 -    .. automethod:: cubicweb.server.session.Session.set_shared_data
158      .. automethod:: cubicweb.server.session.Session.added_in_transaction
159      .. automethod:: cubicweb.server.session.Session.deleted_in_transaction
160 
161      Connection state information:
162 
@@ -1557,32 +1533,10 @@
163      def local_perm_cache(self, value):
164          #base class assign an empty dict:-(
165          assert value == {}
166          pass
167 
168 -    # shared data handling ###################################################
169 -
170 -    @deprecated('[3.19] use session or transaction data')
171 -    def get_shared_data(self, key, default=None, pop=False, txdata=False):
172 -        """return value associated to `key` in session data"""
173 -        if txdata:
174 -            return self._cnx.get_shared_data(key, default, pop, txdata=True)
175 -        else:
176 -            data = self.data
177 -        if pop:
178 -            return data.pop(key, default)
179 -        else:
180 -            return data.get(key, default)
181 -
182 -    @deprecated('[3.19] use session or transaction data')
183 -    def set_shared_data(self, key, value, txdata=False):
184 -        """set value associated to `key` in session data"""
185 -        if txdata:
186 -            return self._cnx.set_shared_data(key, value, txdata=True)
187 -        else:
188 -            self.data[key] = value
189 -
190      # server-side service call #################################################
191 
192      call_service = cnx_meth('call_service')
193 
194      # request interface #######################################################
diff --git a/server/test/unittest_repository.py b/server/test/unittest_repository.py
@@ -170,30 +170,10 @@
195 
196      def test_invalid_cnxid(self):
197          self.assertRaises(BadConnectionId, self.repo.execute, 0, 'Any X')
198          self.assertRaises(BadConnectionId, self.repo.close, None)
199 
200 -    def test_shared_data(self):
201 -        repo = self.repo
202 -        cnxid = repo.connect(self.admlogin, password=self.admpassword)
203 -        repo.set_shared_data(cnxid, 'data', 4)
204 -        cnxid2 = repo.connect(self.admlogin, password=self.admpassword)
205 -        self.assertEqual(repo.get_shared_data(cnxid, 'data'), 4)
206 -        self.assertEqual(repo.get_shared_data(cnxid2, 'data'), None)
207 -        repo.set_shared_data(cnxid2, 'data', 5)
208 -        self.assertEqual(repo.get_shared_data(cnxid, 'data'), 4)
209 -        self.assertEqual(repo.get_shared_data(cnxid2, 'data'), 5)
210 -        repo.get_shared_data(cnxid2, 'data', pop=True)
211 -        self.assertEqual(repo.get_shared_data(cnxid, 'data'), 4)
212 -        self.assertEqual(repo.get_shared_data(cnxid2, 'data'), None)
213 -        repo.close(cnxid)
214 -        repo.close(cnxid2)
215 -        self.assertRaises(BadConnectionId, repo.get_shared_data, cnxid, 'data')
216 -        self.assertRaises(BadConnectionId, repo.get_shared_data, cnxid2, 'data')
217 -        self.assertRaises(BadConnectionId, repo.set_shared_data, cnxid, 'data', 1)
218 -        self.assertRaises(BadConnectionId, repo.set_shared_data, cnxid2, 'data', 1)
219 -
220      def test_check_session(self):
221          repo = self.repo
222          cnxid = repo.connect(self.admlogin, password=self.admpassword)
223          self.assertIsInstance(repo.check_session(cnxid), float)
224          repo.close(cnxid)
@@ -444,23 +424,10 @@
225          self.assertEqual(repo.describe(cnxid, 2), (u'CWGroup', 'system', None, 'system'))
226          repo.close(cnxid)
227          self.assertRaises(BadConnectionId, repo.user_info, cnxid)
228          self.assertRaises(BadConnectionId, repo.describe, cnxid, 1)
229 
230 -    def test_shared_data_api(self):
231 -        repo = self.repo
232 -        cnxid = repo.connect(self.admlogin, password=self.admpassword)
233 -        self.assertEqual(repo.get_shared_data(cnxid, 'data'), None)
234 -        repo.set_shared_data(cnxid, 'data', 4)
235 -        self.assertEqual(repo.get_shared_data(cnxid, 'data'), 4)
236 -        repo.get_shared_data(cnxid, 'data', pop=True)
237 -        repo.get_shared_data(cnxid, 'whatever', pop=True)
238 -        self.assertEqual(repo.get_shared_data(cnxid, 'data'), None)
239 -        repo.close(cnxid)
240 -        self.assertRaises(BadConnectionId, repo.set_shared_data, cnxid, 'data', 0)
241 -        self.assertRaises(BadConnectionId, repo.get_shared_data, cnxid, 'data')
242 -
243      def test_schema_is_relation(self):
244          with self.admin_access.repo_cnx() as cnx:
245              no_is_rset = cnx.execute('Any X WHERE NOT X is ET')
246              self.assertFalse(no_is_rset, no_is_rset.description)
247 
diff --git a/test/unittest_dbapi.py b/test/unittest_dbapi.py
@@ -55,25 +55,10 @@
248          cnx.close()
249          self.assertRaises(ProgrammingError, cnx.user, None)
250          self.assertRaises(ProgrammingError, cnx.entity_metas, 1)
251          self.assertRaises(ProgrammingError, cnx.describe, 1)
252 
253 -    def test_shared_data_api(self):
254 -        cnx = _repo_connect(self.repo, login='anon', password='anon')
255 -        self.assertEqual(cnx.get_shared_data('data'), None)
256 -        cnx.set_shared_data('data', 4)
257 -        self.assertEqual(cnx.get_shared_data('data'), 4)
258 -        cnx.get_shared_data('data', pop=True)
259 -        cnx.get_shared_data('whatever', pop=True)
260 -        self.assertEqual(cnx.get_shared_data('data'), None)
261 -        cnx.set_shared_data('data', 4)
262 -        self.assertEqual(cnx.get_shared_data('data'), 4)
263 -        cnx.close()
264 -        self.assertRaises(ProgrammingError, cnx.check)
265 -        self.assertRaises(ProgrammingError, cnx.set_shared_data, 'data', 0)
266 -        self.assertRaises(ProgrammingError, cnx.get_shared_data, 'data')
267 -
268      def test_web_compatible_request(self):
269          config = cwconfig.CubicWebNoAppConfiguration()
270          cnx = _repo_connect(self.repo, login='admin', password='gingkow')
271          with tempattr(cnx.vreg, 'config', config):
272              cnx.use_web_compatible_requests('http://perdu.com')
diff --git a/web/request.py b/web/request.py
@@ -1069,12 +1069,10 @@
273              self._ = self.__ = unicode
274              self.pgettext = lambda x, y: unicode(y)
275 
276      entity_metas = _cnx_func('entity_metas')
277      source_defs = _cnx_func('source_defs')
278 -    get_shared_data = _cnx_func('get_shared_data')
279 -    set_shared_data = _cnx_func('set_shared_data')
280      describe = _cnx_func('describe') # deprecated XXX
281 
282      # server-side service call #################################################
283 
284      def call_service(self, regid, **kwargs):