Skip to content

Commit

Permalink
Raising a ValueError when a ComponentData is passed to del_component
Browse files Browse the repository at this point in the history
  • Loading branch information
emma58 committed Dec 2, 2024
1 parent f382c1e commit 4dcfc65
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pyomo/core/base/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from pyomo.common.timing import ConstructionTimer
from pyomo.core.base.component import (
Component,
ComponentData,
ActiveComponentData,
ModelComponentFactory,
)
Expand Down Expand Up @@ -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,)
Expand Down

0 comments on commit 4dcfc65

Please sign in to comment.