[hooks] base64-encode extid before inserting it into moved_entities
If we insert the wrong value we're never going to find these entities
again... Closes #5741105.
--- a/hooks/metadata.py Thu Jul 23 09:43:36 2015 +0200
+++ b/hooks/metadata.py Mon Jul 06 14:34:41 2015 +0200
@@ -20,6 +20,7 @@
__docformat__ = "restructuredtext en"
from datetime import datetime
+from base64 import b64encode
from cubicweb.predicates import is_instance
from cubicweb.server import hook
@@ -203,7 +204,9 @@
# to 'moved_entities'. External source will then have consider
# case where `extid2eid` returns a negative eid as 'this entity was
# known but has been moved, ignore it'.
- attrs = {'eid': entity.eid, 'extid': self._cw.entity_metas(entity.eid)['extid']}
+ extid = self._cw.entity_metas(entity.eid)['extid']
+ assert extid is not None
+ attrs = {'eid': entity.eid, 'extid': b64encode(extid).decode('ascii')}
self._cw.system_sql(syssource.sqlgen.insert('moved_entities', attrs), attrs)
attrs = {'type': entity.cw_etype, 'eid': entity.eid, 'extid': None,
'asource': 'system'}
--- a/sobjects/test/unittest_cwxmlparser.py Thu Jul 23 09:43:36 2015 +0200
+++ b/sobjects/test/unittest_cwxmlparser.py Mon Jul 06 14:34:41 2015 +0200
@@ -267,7 +267,11 @@
self.assertEqual(e.cw_source[0].name, 'system')
self.assertEqual(e.reverse_use_email[0].login, 'sthenault')
# test everything is still fine after source synchronization
+ # clear caches to make sure we look at the moved_entities table
+ self.repo._type_source_cache.clear()
+ self.repo._extid_cache.clear()
stats = dfsource.pull_data(cnx, force=True, raise_on_error=True)
+ self.assertEqual(stats['updated'], set((email.eid,)))
rset = cnx.execute('EmailAddress X WHERE X address "syt@logilab.fr"')
self.assertEqual(len(rset), 1)
e = rset.get_entity(0, 0)