From 970f067a6f6a1472b8fe99dbafca30c00a471af7 Mon Sep 17 00:00:00 2001 From: Griatch Date: Sat, 12 Feb 2022 20:19:35 +0100 Subject: [PATCH] Avoid inf recursion when deleting script from at_stop. Resolve #2642 --- evennia/commands/default/building.py | 7 +++++-- evennia/scripts/scripts.py | 18 ++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/evennia/commands/default/building.py b/evennia/commands/default/building.py index c60715e01f..0ce89949bb 100644 --- a/evennia/commands/default/building.py +++ b/evennia/commands/default/building.py @@ -3373,7 +3373,7 @@ class CmdScripts(COMMAND_DEFAULT_CLASS): obj_query = script_query = self.args scripts = self._search_script(script_query) - objects = ObjectDB.objects.object_search(obj_query) + objects = caller.search(obj_query, quiet=True) obj = objects[0] if objects else None if not self.switches: @@ -3461,7 +3461,10 @@ class CmdScripts(COMMAND_DEFAULT_CLASS): ) caller.msg("\n".join(msgs)) if "delete" not in self.switches: - ScriptEvMore(caller, [script], session=self.session) + if script and script.pk: + ScriptEvMore(caller, [script], session=self.session) + else: + caller.msg("Script was deleted automatically.") else: caller.msg("No scripts found.") diff --git a/evennia/scripts/scripts.py b/evennia/scripts/scripts.py index eeed1473c9..d24ddd4a3c 100644 --- a/evennia/scripts/scripts.py +++ b/evennia/scripts/scripts.py @@ -316,9 +316,12 @@ class ScriptBase(ScriptDB, metaclass=TypeclassBase): Stop task runner and delete the task. """ + task_stopped = False task = self.ndb._task if task and task.running: task.stop() + task_stopped = True + self.ndb._task = None self.db_is_active = False @@ -328,7 +331,8 @@ class ScriptBase(ScriptDB, metaclass=TypeclassBase): self.db._manually_paused = None self.save(update_fields=["db_is_active"]) - self.at_stop(**kwargs) + if task_stopped: + self.at_stop(**kwargs) def _step_errback(self, e): """ @@ -449,17 +453,11 @@ class ScriptBase(ScriptDB, metaclass=TypeclassBase): # autostart the script self._start_task(force_restart=True) - def delete(self, stop_task=True): + def delete(self): """ Delete the Script. Normally stops any timer task. This fires at_script_delete before deletion. - Args: - stop_task (bool, optional): If unset, the task will not be stopped - when this method is called. The main reason for setting this to False - is if wanting to delete the script from the at_stop method - setting - this will then avoid an infinite recursion. - Returns: bool: If deletion was successful or not. Only time this can fail would be if the script was already previously deleted, or `at_script_delete` returns @@ -468,8 +466,8 @@ class ScriptBase(ScriptDB, metaclass=TypeclassBase): """ if not self.pk or not self.at_script_delete(): return False - if stop_task: - self._stop_task() + + self._stop_task() super().delete() return True