0
0
Fork 0

remove_pou_from_task: del-by-index first + verify removal actually happened

ScriptPouObjectCollection.remove(name) can return without effect on
SP21 (no exception, entry persists -- observed after a program rename
left a stale task call). Delete by index first and fail loud if the
name is still in the call list after save.
This commit is contained in:
Karstein Phobic Nyvold Kvistad 2026-07-24 11:43:12 +02:00
parent 340fed23f3
commit ba22ec1c6d

View file

@ -76,6 +76,16 @@ try:
removed = False
errors = []
# del by index FIRST: ScriptPouObjectCollection.remove(name) can return
# without effect (no exception, entry persists -- observed SP21 Sea Leopard
# 2026-07-24 after a program rename left a stale call). Index deletion is
# deterministic; verify afterwards instead of trusting the call.
if not removed:
try:
del pous[before.index(POU_NAME)]; removed = True
except Exception as e:
errors.append("del[i]: %s" % e)
if not removed:
try:
pous.remove(POU_NAME); removed = True
@ -108,6 +118,10 @@ try:
except Exception:
pass
if POU_NAME in after:
raise RuntimeError("Removal reported success but '%s' is STILL in task '%s' call list: %s" % (
POU_NAME, TASK_NAME, ", ".join(after)))
print("POU '%s' removed from task '%s'." % (POU_NAME, TASK_NAME))
print("Task '%s' now calls: %s" % (TASK_NAME, ", ".join(after) if after else "(none)"))
print("SCRIPT_SUCCESS: POU call removed from task.")