[hooks] base64-encode extid before inserting it into moved_entities

authorJulien Cristau <julien.cristau@logilab.fr>
changeset225eb2e8f58f
branchdefault
phasedraft
hiddenyes
parent revision#83b87bdefd0e [server] missing import
child revision<not specified>
files modified by this revision
hooks/metadata.py
# HG changeset patch
# User Julien Cristau <julien.cristau@logilab.fr>
# Date 1436186081 -7200
# Mon Jul 06 14:34:41 2015 +0200
# Node ID 225eb2e8f58f61107e86e02a5266892b456989fd
# Parent 83b87bdefd0e5c724aabbc1f2bf8a9ee6c6d7ac5
[hooks] base64-encode extid before inserting it into moved_entities

diff --git a/hooks/metadata.py b/hooks/metadata.py
@@ -18,10 +18,11 @@
1  """Core hooks: set generic metadata"""
2 
3  __docformat__ = "restructuredtext en"
4 
5  from datetime import datetime
6 +from base64 import b64encode
7 
8  from cubicweb.predicates import is_instance
9  from cubicweb.server import hook
10  from cubicweb.server.edition import EditedEntity
11 
@@ -201,11 +202,13 @@
12              # we don't want the moved entity to be reimported later.  To
13              # distinguish this state, move the record from the 'entities' table
14              # to 'moved_entities'.  External source will then have consider
15              # case where `extid2eid` returns a negative eid as 'this entity was
16              # known but has been moved, ignore it'.
17 -            attrs = {'eid': entity.eid, 'extid': self._cw.entity_metas(entity.eid)['extid']}
18 +            extid = self._cw.entity_metas(entity.eid)['extid']
19 +            assert extid is not None
20 +            attrs = {'eid': entity.eid, 'extid': b64encode(extid)}
21              self._cw.system_sql(syssource.sqlgen.insert('moved_entities', attrs), attrs)
22              attrs = {'type': entity.cw_etype, 'eid': entity.eid, 'extid': None,
23                       'asource': 'system'}
24              self._cw.system_sql(syssource.sqlgen.update('entities', attrs, ['eid']), attrs)
25              # register an operation to update repository/sources caches