Better checks for pk in delete command. Update how the delete method of objects avoid recursive calls. Resolves #1453.

This commit is contained in:
Griatch 2017-09-30 12:00:42 +02:00
parent 0ba913332a
commit a6ed6ff5ea
2 changed files with 28 additions and 36 deletions

View file

@ -647,29 +647,32 @@ class CmdDestroy(COMMAND_DEFAULT_CLASS):
def delobj(obj):
# helper function for deleting a single object
string = ""
objname = obj.name
if not (obj.access(caller, "control") or obj.access(caller, 'delete')):
return "\nYou don't have permission to delete %s." % objname
if obj.account and 'override' not in self.switches:
return "\nObject %s is controlled by an active account. Use /override to delete anyway." % objname
if obj.dbid == int(settings.DEFAULT_HOME.lstrip("#")):
return "\nYou are trying to delete |c%s|n, which is set as DEFAULT_HOME. " \
"Re-point settings.DEFAULT_HOME to another " \
"object before continuing." % objname
had_exits = hasattr(obj, "exits") and obj.exits
had_objs = hasattr(obj, "contents") and any(obj for obj in obj.contents
if not (hasattr(obj, "exits") and obj not in obj.exits))
# do the deletion
okay = obj.delete()
if not okay:
string += "\nERROR: %s not deleted, probably because delete() returned False." % objname
if not obj.pk:
string = "\nObject %s was already deleted." % obj.db_key
else:
string += "\n%s was destroyed." % objname
if had_exits:
string += " Exits to and from %s were destroyed as well." % objname
if had_objs:
string += " Objects inside %s were moved to their homes." % objname
objname = obj.name
if not (obj.access(caller, "control") or obj.access(caller, 'delete')):
return "\nYou don't have permission to delete %s." % objname
if obj.account and 'override' not in self.switches:
return "\nObject %s is controlled by an active account. Use /override to delete anyway." % objname
if obj.dbid == int(settings.DEFAULT_HOME.lstrip("#")):
return "\nYou are trying to delete |c%s|n, which is set as DEFAULT_HOME. " \
"Re-point settings.DEFAULT_HOME to another " \
"object before continuing." % objname
had_exits = hasattr(obj, "exits") and obj.exits
had_objs = hasattr(obj, "contents") and any(obj for obj in obj.contents
if not (hasattr(obj, "exits") and obj not in obj.exits))
# do the deletion
okay = obj.delete()
if not okay:
string += "\nERROR: %s not deleted, probably because delete() returned False." % objname
else:
string += "\n%s was destroyed." % objname
if had_exits:
string += " Exits to and from %s were destroyed as well." % objname
if had_objs:
string += " Objects inside %s were moved to their homes." % objname
return string
objs = []

View file

@ -830,8 +830,6 @@ class DefaultObject(with_metaclass(TypeclassBase, ObjectDB)):
new_key = new_key or find_clone_key()
return ObjectDB.objects.copy_object(self, new_key=new_key)
delete_iter = 0
def delete(self):
"""
Deletes this object. Before deletion, this method makes sure
@ -847,20 +845,11 @@ class DefaultObject(with_metaclass(TypeclassBase, ObjectDB)):
if not _ScriptDB:
from evennia.scripts.models import ScriptDB as _ScriptDB
if self.delete_iter > 0:
# make sure to only call delete once on this object
# (avoid recursive loops)
if not self.pk or not self.at_object_delete():
# This object has already been deleted,
# or the pre-delete check return False
return False
if not self.at_object_delete():
# this is an extra pre-check
# run before deletion field-related properties
# is kicked into gear.
self.delete_iter = 0
return False
self.delete_iter += 1
# See if we need to kick the account off.
for session in self.sessions.all():