From ba22ec1c6d054c25bc0a1a0d62f47afa17b9d7c8 Mon Sep 17 00:00:00 2001 From: Karstein Phobic Nyvold Kvistad Date: Fri, 24 Jul 2026 11:43:12 +0200 Subject: [PATCH] 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. --- src/scripts/remove_pou_from_task.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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.")