Avoid inf recursion when deleting script from at_stop. Resolve #2642
This commit is contained in:
parent
a19211f3fd
commit
29430d8d0f
2 changed files with 13 additions and 12 deletions
|
|
@ -3373,7 +3373,7 @@ class CmdScripts(COMMAND_DEFAULT_CLASS):
|
||||||
obj_query = script_query = self.args
|
obj_query = script_query = self.args
|
||||||
|
|
||||||
scripts = self._search_script(script_query)
|
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
|
obj = objects[0] if objects else None
|
||||||
|
|
||||||
if not self.switches:
|
if not self.switches:
|
||||||
|
|
@ -3461,7 +3461,10 @@ class CmdScripts(COMMAND_DEFAULT_CLASS):
|
||||||
)
|
)
|
||||||
caller.msg("\n".join(msgs))
|
caller.msg("\n".join(msgs))
|
||||||
if "delete" not in self.switches:
|
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:
|
else:
|
||||||
caller.msg("No scripts found.")
|
caller.msg("No scripts found.")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -316,9 +316,12 @@ class ScriptBase(ScriptDB, metaclass=TypeclassBase):
|
||||||
Stop task runner and delete the task.
|
Stop task runner and delete the task.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
task_stopped = False
|
||||||
task = self.ndb._task
|
task = self.ndb._task
|
||||||
if task and task.running:
|
if task and task.running:
|
||||||
task.stop()
|
task.stop()
|
||||||
|
task_stopped = True
|
||||||
|
|
||||||
self.ndb._task = None
|
self.ndb._task = None
|
||||||
self.db_is_active = False
|
self.db_is_active = False
|
||||||
|
|
||||||
|
|
@ -328,7 +331,8 @@ class ScriptBase(ScriptDB, metaclass=TypeclassBase):
|
||||||
self.db._manually_paused = None
|
self.db._manually_paused = None
|
||||||
|
|
||||||
self.save(update_fields=["db_is_active"])
|
self.save(update_fields=["db_is_active"])
|
||||||
self.at_stop(**kwargs)
|
if task_stopped:
|
||||||
|
self.at_stop(**kwargs)
|
||||||
|
|
||||||
def _step_errback(self, e):
|
def _step_errback(self, e):
|
||||||
"""
|
"""
|
||||||
|
|
@ -449,17 +453,11 @@ class ScriptBase(ScriptDB, metaclass=TypeclassBase):
|
||||||
# autostart the script
|
# autostart the script
|
||||||
self._start_task(force_restart=True)
|
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
|
Delete the Script. Normally stops any timer task. This fires at_script_delete before
|
||||||
deletion.
|
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:
|
Returns:
|
||||||
bool: If deletion was successful or not. Only time this can fail would be if
|
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
|
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():
|
if not self.pk or not self.at_script_delete():
|
||||||
return False
|
return False
|
||||||
if stop_task:
|
|
||||||
self._stop_task()
|
self._stop_task()
|
||||||
super().delete()
|
super().delete()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue