From: Benoît Pin Date: Wed, 9 Jul 2014 08:16:16 +0000 (+0200) Subject: Bugfix : la connexion Solr peut se volatiliser plus vite que le hook de transaction… X-Git-Url: https://scm.cri.ensmp.fr/git/Plinn.git/commitdiff_plain/a4cb4d96face514924387d34746b3148848ac092?hp=-c Bugfix : la connexion Solr peut se volatiliser plus vite que le hook de transaction… --- a4cb4d96face514924387d34746b3148848ac092 diff --git a/catalog.py b/catalog.py index 05cbd59..0a457f8 100644 --- a/catalog.py +++ b/catalog.py @@ -22,17 +22,20 @@ _VOLATILE_SOLR_NAME = '_v_solrConnection' class SolrTransactionHook : ''' commit solr couplé sur le commit de la ZODB ''' - def __init__(self, context) : + def __init__(self, context, con) : self.context = context + self.con = con def __call__(self, status) : - con = getattr(self.context, _VOLATILE_SOLR_NAME) if status : - con.commit() - con.close() + self.con.commit() + self.con.close() else : - con.close() - delattr(self.context, _VOLATILE_SOLR_NAME) + self.con.close() + try : + delattr(self.context, _VOLATILE_SOLR_NAME) + except AttributeError : + pass class CatalogTool(BaseCatalogTool) : meta_type = 'Plinn Catalog' @@ -54,7 +57,7 @@ class CatalogTool(BaseCatalogTool) : con = SolrConnection(self.solr_url) setattr(self, _VOLATILE_SOLR_NAME, con) txn = transaction.get() - txn.addAfterCommitHook(SolrTransactionHook(self)) + txn.addAfterCommitHook(SolrTransactionHook(self, con)) return getattr(self, _VOLATILE_SOLR_NAME) security.declarePrivate('solrAdd')