[ms repository] when an exception is raised during extid2eid and no rollback is done, some manual cleanups have to be done (closes #1993420)
--- a/server/repository.py Fri Oct 14 08:49:58 2011 +0200
+++ b/server/repository.py Fri Oct 14 08:50:09 2011 +0200
@@ -1085,6 +1085,9 @@
entity = source.before_entity_insertion(
session, extid, etype, eid, sourceparams)
if source.should_call_hooks:
+ # get back a copy of operation for later restore if necessary,
+ # see below
+ pending_operations = session.pending_operations[:]
self.hm.call_hooks('before_add_entity', session, entity=entity)
self.add_info(session, entity, source, extid, complete=complete)
source.after_entity_insertion(session, extid, entity, sourceparams)
@@ -1096,6 +1099,16 @@
except Exception:
if commit or free_cnxset:
session.rollback(free_cnxset)
+ else:
+ # XXX do some cleanup manually so that the transaction has a
+ # chance to be commited, with simply this entity discarded
+ self._extid_cache.pop(cachekey, None)
+ self._type_source_cache.pop(eid, None)
+ if 'entity' in locals():
+ hook.CleanupDeletedEidsCacheOp.get_instance(session).add_data(entity.eid)
+ self.system_source.delete_info_multi(session, [entity], uri)
+ if source.should_call_hooks:
+ session._threaddata.pending_operations = pending_operations
raise
def add_info(self, session, entity, source, extid=None, complete=True):
--- a/server/sources/datafeed.py Fri Oct 14 08:49:58 2011 +0200
+++ b/server/sources/datafeed.py Fri Oct 14 08:50:09 2011 +0200
@@ -297,7 +297,9 @@
complete=False, commit=False,
sourceparams=sourceparams)
except ValidationError, ex:
- self.source.error('error while creating %s: %s', etype, ex)
+ # XXX use critical so they are seen during tests. Should consider
+ # raise_on_error instead?
+ self.source.critical('error while creating %s: %s', etype, ex)
return None
if eid < 0:
# entity has been moved away from its original source