[ccplugin] do not crash if an entity failed to serialize

otherwise the import just hand forever.

authorDavid Douard <david.douard@logilab.fr>
changeset1c4e7b35e611
branchdefault
phasepublic
hiddenno
parent revision#6bd462ae5a6c Added tag 0.5.1, debian/0.5.1-1, centos/0.5.1-1 for changeset d422c1e42a8a
child revision#46ca26089efb [hook] delete_doc is a staticmethod => remove `self` argument
files modified by this revision
cubicweb_elasticsearch/ccplugin.py
# HG changeset patch
# User David Douard <david.douard@logilab.fr>
# Date 1493882661 -7200
# Thu May 04 09:24:21 2017 +0200
# Node ID 1c4e7b35e611717b8167756ac269d365500c8597
# Parent 6bd462ae5a6c28925a07f17f3fc4f92a5dc5658b
[ccplugin] do not crash if an entity failed to serialize

otherwise the import just hand forever.

diff --git a/cubicweb_elasticsearch/ccplugin.py b/cubicweb_elasticsearch/ccplugin.py
@@ -100,12 +100,18 @@
1              rset = cnx.execute(rql)
2              cnx.info(u'[{}] indexing {} {} entities'.format(index_name, len(rset), etype))
3              cnx.debug(u'RQL: {}'.format(rql))
4 
5              for entity in rset.entities():
6 -                serializer = entity.cw_adapt_to('IFullTextIndexSerializable')
7 -                json = serializer.serialize()
8 +                try:
9 +                    serializer = entity.cw_adapt_to('IFullTextIndexSerializable')
10 +                    json = serializer.serialize()
11 +                except Exception as e:
12 +                    cnx.error('[{}] Failed to serialize entity {} ({})'.format(
13 +                        index_name, entity.eid, etype))
14 +                    continue
15 +
16                  if not dry_run and json:
17                      # Entities with
18                      # fulltext_containers relations return their container
19                      # IFullTextIndex serializer , therefor the "id" and
20                      # "doc_type" in kwargs bellow must be container data.