Make common typeclass.delete return True/False to match Object.delete api for consistency. Resolve #2398

This commit is contained in:
Griatch 2021-11-03 23:18:50 +01:00
parent 00b29a693d
commit 58f86fd3d7
4 changed files with 38 additions and 5 deletions

View file

@ -114,6 +114,8 @@ Up requirements to Django 3.2+, Twisted 21+
`"Evennia webclient (websocket:firefox)"` or `"evennia webclient (ajax:chrome)"`.
- `TagHandler.add/has(tag=...)` kwarg changed to `add/has(key=...)` for consistency
with other handlers.
- Make `DefaultScript.delete`, `DefaultChannel.delete` and `DefaultAccount.delete` return
bool True/False if deletion was successful (like `DefaultObject.delete` before them)
### Evennia 0.9.5 (2019-2020)

View file

@ -853,6 +853,12 @@ class DefaultAccount(AccountDB, metaclass=TypeclassBase):
`*args` and `**kwargs` are passed on to the base delete
mechanism (these are usually not used).
Return:
bool: If deletion was successful. Only time it fails would be
if the Account was already deleted. Note that even on a failure,
connected resources (nicks/aliases etc) will still have been
deleted.
"""
for session in self.sessions.all():
# unpuppeting all objects and disconnecting the user, if any
@ -868,7 +874,11 @@ class DefaultAccount(AccountDB, metaclass=TypeclassBase):
self.attributes.clear()
self.nicks.clear()
self.aliases.clear()
if not self.pk:
return False
super().delete(*args, **kwargs)
return True
# methods inherited from database model

View file

@ -399,12 +399,20 @@ class DefaultChannel(ChannelDB, metaclass=TypeclassBase):
"""
Deletes channel.
Returns:
bool: If deletion was successful. Only time it can fail would be
if channel was already deleted. Even if it were to fail, all subscribers
will be disconnected.
"""
self.attributes.clear()
self.aliases.clear()
for subscriber in self.subscriptions.all():
self.disconnect(subscriber)
if not self.pk:
return False
super().delete()
return True
def channel_prefix(self):
"""

View file

@ -447,11 +447,18 @@ class ScriptBase(ScriptDB, metaclass=TypeclassBase):
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
False.
"""
if not self.pk or not self.at_script_delete():
return False
if stop_task:
self._stop_task()
self.at_script_delete()
super().delete()
return True
def at_script_creation(self):
"""
@ -462,10 +469,13 @@ class ScriptBase(ScriptDB, metaclass=TypeclassBase):
def at_script_delete(self):
"""
Called when script is deleted, after at_stop.
Called when script is deleted, before the script timer stops.
Returns:
bool: If False, deletion is aborted.
"""
pass
return True
def is_valid(self):
"""
@ -725,10 +735,13 @@ class DefaultScript(ScriptBase):
def at_script_delete(self):
"""
Called when the Script is deleted, after at_stop().
Called when the Script is deleted, before stopping the timer.
Returns:
bool: If False, the deletion is aborted.
"""
pass
return True
def at_server_reload(self):
"""