From 67dc11849f4bd9145647dce317ed144f344705cc Mon Sep 17 00:00:00 2001 From: Griatch Date: Sun, 14 Oct 2012 20:21:53 +0200 Subject: [PATCH] Added a check for 1st level recursion of location. So self.location=self will no longer work. I did not add a full recursive check (it would need to go through all contents of the object and their contents etc) since this is expensive for something that should usually not be a common error. Further checks could be added higher up in the build commands if location-loops are considered a big problem. Resolves Issue 296. --- src/objects/models.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/objects/models.py b/src/objects/models.py index 9b37780735..eded84b1e5 100644 --- a/src/objects/models.py +++ b/src/objects/models.py @@ -285,18 +285,31 @@ class ObjectDB(TypedObject): loc = _GA(location, "dbobj") else: loc = location + if loc == self: + # block 1st level recursion; best to defer having to do + # a full recursive check of location loops if possible - + # (it's rather expensive) this could be checked higher up + # if a problem. + raise RuntimeError + # set the location _set_cache(self, "location", loc) # update the contents of each location if old_loc: _GA(_GA(old_loc, "dbobj"), "contents_update")(self, remove=True) if loc: _GA(loc, "contents_update")(_GA(self, "typeclass")) + except RuntimeError: + string = "Cannot set location: " + string += "%s.location = %s would create a location-loop." % (self.key, location) + _GA(self, "msg")(_(string)) + logger.log_trace(string) + raise RuntimeError(string) except Exception: string = "Cannot set location: " - string += "%s is not a valid location." - _GA(self, "msg")(_(string) % location) + string += "%s is not a valid location." % location + _GA(self, "msg")(_(string)) logger.log_trace(string) - raise + raise Exception(string) #@location.deleter def __location_del(self): "Deleter. Allows for del self.location"