From 3b6572ea2dfcf2eb35a803c72a88019f02f55679 Mon Sep 17 00:00:00 2001
From: Tomasz Bold <tomasz.bold@gmail.com>
Date: Mon, 25 Feb 2019 14:50:59 +0100
Subject: [PATCH] CA on which the foreach_component was used is not mergable

---
 Control/AthenaConfiguration/python/ComponentAccumulator.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/Control/AthenaConfiguration/python/ComponentAccumulator.py b/Control/AthenaConfiguration/python/ComponentAccumulator.py
index 965401231f77..eeb1523b89da 100644
--- a/Control/AthenaConfiguration/python/ComponentAccumulator.py
+++ b/Control/AthenaConfiguration/python/ComponentAccumulator.py
@@ -42,6 +42,7 @@ class ComponentAccumulator(object):
 
         #To check if this accumulator was merged:
         self._wasMerged=False
+        self._isMergable=True
 
 
     def empty(self):
@@ -451,7 +452,9 @@ class ComponentAccumulator(object):
 
         if not isinstance(other,ComponentAccumulator):
             raise TypeError("Attempt merge wrong type %s. Only instances of ComponentAccumulator can be added" % type(other).__name__)
-
+        
+        if not other._isMergable:
+            raise ConfigurationError("Attempted to merge the accumulator that was unsafely manipulated (likely with foreach_component, ...)")
 
         if not Configurable.configurableRun3Behavior:
             raise ConfigurationError("discoverd Configurable.configurableRun3Behavior=False while working woth ComponentAccumulator")
@@ -883,6 +886,7 @@ def foreach_component(componentAccumulator, path):
    PublicTools - are located under ToolSvc/ and type/instance_name is used
    Services - located under SvcMgr/ and type/instance_name is used
    """
+   componentAccumulator._isMergable=False
    return PropSetterProxy(componentAccumulator, path)
 
 
-- 
GitLab