diff --git a/pyomo/core/base/block.py b/pyomo/core/base/block.py index 656bf6008c4..de94dbe8ae8 100644 --- a/pyomo/core/base/block.py +++ b/pyomo/core/base/block.py @@ -34,6 +34,7 @@ from pyomo.common.timing import ConstructionTimer from pyomo.core.base.component import ( Component, + ComponentData, ActiveComponentData, ModelComponentFactory, ) @@ -1139,6 +1140,14 @@ def del_component(self, name_or_object): # return name = obj.local_name + if isinstance(obj, ComponentData) and not isinstance(obj, Component): + raise ValueError( + "Argument '%s' to del_component is a ComponentData object. Please " + "use the Python 'del' function to delete members of indexed " + "Pyomo objects. The del_component function can only be used to " + "delete IndexedComponents and ScalarComponents." % name + ) + if name in self._Block_reserved_words: raise ValueError( "Attempting to delete a reserved block component:\n\t%s" % (obj.name,)