# HG changeset patch # User Aurelien Campeas # Date 1399033574 -7200 # Node ID b7b71be569cfd0f436ba8d08f2af90e84b5c597e # Parent 71a45642b3d27f6b28fddf754a37d5d197a7448c deprecate get/set_shared_data API Session or transaction data must be used instead. We must forward .transaction_data to web/request from which it was missing (this is indeed a _cw object API). Closes #3799036. diff -r 71a45642b3d2 -r b7b71be569cf dbapi.py --- a/dbapi.py Wed Jun 11 14:46:48 2014 +0200 +++ b/dbapi.py Fri May 02 14:26:14 2014 +0200 @@ -343,10 +343,12 @@ # low level session data management ####################################### + @deprecated('[3.19] use session or transaction data') def get_shared_data(self, key, default=None, pop=False, txdata=False): """see :meth:`Connection.get_shared_data`""" return self.cnx.get_shared_data(key, default, pop, txdata) + @deprecated('[3.19] use session or transaction data') def set_shared_data(self, key, value, txdata=False, querydata=None): """see :meth:`Connection.set_shared_data`""" if querydata is not None: diff -r 71a45642b3d2 -r b7b71be569cf entity.py --- a/entity.py Wed Jun 11 14:46:48 2014 +0200 +++ b/entity.py Fri May 02 14:26:14 2014 +0200 @@ -551,14 +551,12 @@ def _cw_update_attr_cache(self, attrcache): # if context is a repository session, don't consider dont-cache-attrs as - # the instance already hold modified values and loosing them could + # the instance already holds modified values and loosing them could # introduce severe problems - get_set = partial(self._cw.get_shared_data, default=(), txdata=True, - pop=True) - uncached_attrs = set() - uncached_attrs.update(get_set('%s.storage-special-process-attrs' % self.eid)) + trdata = self._cw.transaction_data + uncached_attrs = trdata.get('%s.storage-special-process-attrs' % self.eid, set()) if self._cw.is_request: - uncached_attrs.update(get_set('%s.dont-cache-attrs' % self.eid)) + uncached_attrs.update(trdata.get('%s.dont-cache-attrs' % self.eid, set())) for attr in uncached_attrs: attrcache.pop(attr, None) self.cw_attr_cache.pop(attr, None) diff -r 71a45642b3d2 -r b7b71be569cf hooks/metadata.py --- a/hooks/metadata.py Wed Jun 11 14:46:48 2014 +0200 +++ b/hooks/metadata.py Fri May 02 14:26:14 2014 +0200 @@ -46,7 +46,7 @@ edited['creation_date'] = timestamp if not edited.get('modification_date'): edited['modification_date'] = timestamp - if not self._cw.get_shared_data('do-not-insert-cwuri'): + if not self._cw.transaction_data.get('do-not-insert-cwuri'): cwuri = u'%s%s' % (self._cw.base_url(), self.entity.eid) edited.setdefault('cwuri', cwuri) diff -r 71a45642b3d2 -r b7b71be569cf repoapi.py --- a/repoapi.py Wed Jun 11 14:46:48 2014 +0200 +++ b/repoapi.py Fri May 02 14:26:14 2014 +0200 @@ -247,6 +247,10 @@ get_shared_data = _srv_cnx_func('get_shared_data') set_shared_data = _srv_cnx_func('set_shared_data') + @property + def transaction_data(self): + return self._cnx.transaction_data + # meta-data accessors ###################################################### @_open_only diff -r 71a45642b3d2 -r b7b71be569cf server/repository.py --- a/server/repository.py Wed Jun 11 14:46:48 2014 +0200 +++ b/server/repository.py Fri May 02 14:26:14 2014 +0200 @@ -746,6 +746,7 @@ """ return self._get_session(sessionid, setcnxset=False).timestamp + @deprecated('[3.19] use session or transaction data') def get_shared_data(self, sessionid, key, default=None, pop=False, txdata=False): """return value associated to key in the session's data dictionary or session's transaction's data if `txdata` is true. @@ -758,6 +759,7 @@ session = self._get_session(sessionid, setcnxset=False) return session.get_shared_data(key, default, pop, txdata) + @deprecated('[3.19] use session or transaction data') def set_shared_data(self, sessionid, key, value, txdata=False): """set value associated to `key` in shared data diff -r 71a45642b3d2 -r b7b71be569cf server/session.py --- a/server/session.py Wed Jun 11 14:46:48 2014 +0200 +++ b/server/session.py Fri May 02 14:26:14 2014 +0200 @@ -549,6 +549,7 @@ return self._rewriter @_open_only + @deprecated('[3.19] use session or transaction data') def get_shared_data(self, key, default=None, pop=False, txdata=False): """return value associated to `key` in session data""" if txdata: @@ -561,6 +562,7 @@ return data.get(key, default) @_open_only + @deprecated('[3.19] use session or transaction data') def set_shared_data(self, key, value, txdata=False): """set value associated to `key` in session data""" if txdata: @@ -1558,6 +1560,7 @@ # shared data handling ################################################### + @deprecated('[3.19] use session or transaction data') def get_shared_data(self, key, default=None, pop=False, txdata=False): """return value associated to `key` in session data""" if txdata: @@ -1569,6 +1572,7 @@ else: return data.get(key, default) + @deprecated('[3.19] use session or transaction data') def set_shared_data(self, key, value, txdata=False): """set value associated to `key` in session data""" if txdata: diff -r 71a45642b3d2 -r b7b71be569cf test/unittest_entity.py --- a/test/unittest_entity.py Wed Jun 11 14:46:48 2014 +0200 +++ b/test/unittest_entity.py Fri May 02 14:26:14 2014 +0200 @@ -366,6 +366,7 @@ self.assertEqual(rql, 'Any S,AA,AB,AC,AD ORDERBY AA ' 'WHERE NOT S use_email O, O eid %(x)s, S is_instance_of CWUser, ' 'S login AA, S firstname AB, S surname AC, S modification_date AD') + req.cnx.commit() rperms = self.schema['EmailAddress'].permissions['read'] clear_cache(self.schema['EmailAddress'], 'get_groups') clear_cache(self.schema['EmailAddress'], 'get_rqlexprs') @@ -700,7 +701,7 @@ e.cw_attr_cache['data_name'] = 'an html file' e.cw_attr_cache['data_format'] = 'text/html' e.cw_attr_cache['data_encoding'] = 'ascii' - e._cw.transaction_data = {} # XXX req should be a session + e._cw.transaction_data.clear() words = e.cw_adapt_to('IFTIndexable').get_words() words['C'].sort() self.assertEqual({'C': sorted(['an', 'html', 'file', 'du', 'html', 'some', 'data'])}, diff -r 71a45642b3d2 -r b7b71be569cf web/request.py --- a/web/request.py Wed Jun 11 14:46:48 2014 +0200 +++ b/web/request.py Fri May 02 14:26:14 2014 +0200 @@ -1031,6 +1031,10 @@ self.session = DBAPISession(None) self.cnx = self.user = _NeedAuthAccessMock() + @property + def transaction_data(self): + return self.cnx.transaction_data + def set_cnx(self, cnx): self.cnx = cnx self.session = cnx._session diff -r 71a45642b3d2 -r b7b71be569cf web/views/editcontroller.py --- a/web/views/editcontroller.py Wed Jun 11 14:46:48 2014 +0200 +++ b/web/views/editcontroller.py Fri May 02 14:26:14 2014 +0200 @@ -178,7 +178,7 @@ form = req.form # so we're able to know the main entity from the repository side if '__maineid' in form: - req.set_shared_data('__maineid', form['__maineid'], txdata=True) + req.transaction_data['__maineid'] = form['__maineid'] # no specific action, generic edition self._to_create = req.data['eidmap'] = {} # those two data variables are used to handle relation from/to entities