Skip to content

Commit 7e5c8e3

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 836db05 commit 7e5c8e3

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
@@ -1216,29 +1216,25 @@ def _set_method_helper(
12161216
dict() which stores the new override variables list,
12171217
"""
12181218

1219-
inputdata_status: dict[str, bool] = {}
12201219
for key, val in inputdata.items():
12211220
if key not in classdata:
12221221
raise ModelicaSystemError("Unhandled case in setMethodHelper.apply_single() - "
12231222
f"{repr(key)} is not a {repr(datatype)} variable")
12241223

1225-
status = False
12261224
if datatype == "parameter" and not self.isParameterChangeable(key):
1227-
logger.debug(f"It is not possible to set the parameter {repr(key)}. It seems to be "
1228-
"structural, final, protected, evaluated or has a non-constant binding. "
1229-
"Use sendExpression(...) and rebuild the model using buildModel() API; example: "
1230-
"sendExpression(\"setParameterValue("
1231-
f"{self._model_name}, {key}, {val if val is not None else '<?value?>'}"
1232-
")\") ")
1233-
else:
1234-
classdata[key] = val
1235-
if overwritedata is not None:
1236-
overwritedata[key] = val
1237-
status = True
1238-
1239-
inputdata_status[key] = status
1225+
raise ModelicaSystemError(f"It is not possible to set the parameter {repr(key)}. It seems to be "
1226+
"structural, final, protected, evaluated or has a non-constant binding. "
1227+
"Use sendExpression(...) and rebuild the model using buildModel() API; "
1228+
"command to set the parameter before rebuilding the model: "
1229+
"sendExpression(\"setParameterValue("
1230+
f"{self._model_name}, {key}, {val if val is not None else '<?value?>'}"
1231+
")\").")
1232+
1233+
classdata[key] = val
1234+
if overwritedata is not None:
1235+
overwritedata[key] = val
12401236

1241-
return all(inputdata_status.values())
1237+
return True
12421238

12431239
def isParameterChangeable(
12441240
self,

0 commit comments

Comments
 (0)