diff --git a/src/scripts/remove_pou_from_task.py b/src/scripts/remove_pou_from_task.py index 290d1d5..9b35350 100644 --- a/src/scripts/remove_pou_from_task.py +++ b/src/scripts/remove_pou_from_task.py @@ -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.")