Skip to content

Commit 259934d

Browse files
committed
[ModelicaSystem._set_method_helper] fail if parameter is *NOT* changeable
* if this happens, the result would be unexpected * fail early, fail hard to indicate this to the user * simplify code
1 parent 340eac4 commit 259934d

1 file changed

Lines changed: 12 additions & 16 deletions

File tree

OMPython/ModelicaSystem.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,29 +1203,25 @@ def _set_method_helper(
12031203
dict() which stores the new override variables list,
12041204
"""
12051205

1206-
inputdata_status: dict[str, bool] = {}
12071206
for key, val in inputdata.items():
12081207
if key not in classdata:
12091208
raise ModelicaSystemError("Unhandled case in setMethodHelper.apply_single() - "
12101209
f"{repr(key)} is not a {repr(datatype)} variable")
12111210

1212-
status = False
12131211
if datatype == "parameter" and not self.isParameterChangeable(key):
1214-
logger.debug(f"It is not possible to set the parameter {repr(key)}. It seems to be "
1215-
"structural, final, protected, evaluated or has a non-constant binding. "
1216-
"Use sendExpression(...) and rebuild the model using buildModel() API; example: "
1217-
"sendExpression(\"setParameterValue("
1218-
f"{self._model_name}, {key}, {val if val is not None else '<?value?>'}"
1219-
")\") ")
1220-
else:
1221-
classdata[key] = val
1222-
if overwritedata is not None:
1223-
overwritedata[key] = val
1224-
status = True
1225-
1226-
inputdata_status[key] = status
1212+
raise ModelicaSystemError(f"It is not possible to set the parameter {repr(key)}. It seems to be "
1213+
"structural, final, protected, evaluated or has a non-constant binding. "
1214+
"Use sendExpression(...) and rebuild the model using buildModel() API; "
1215+
"command to set the parameter before rebuilding the model: "
1216+
"sendExpression(\"setParameterValue("
1217+
f"{self._model_name}, {key}, {val if val is not None else '<?value?>'}"
1218+
")\").")
1219+
1220+
classdata[key] = val
1221+
if overwritedata is not None:
1222+
overwritedata[key] = val
12271223

1228-
return all(inputdata_status.values())
1224+
return True
12291225

12301226
def isParameterChangeable(
12311227
self,

0 commit comments

Comments
 (0)