Make new-style facet deletion more robust
authorJeremy Stanley <fungi@yuggoth.org>
Thu, 9 Nov 2017 09:54:38 +0000 (09:54 +0000)
committerJeremy Stanley <fungi@yuggoth.org>
Thu, 9 Nov 2017 09:54:38 +0000 (09:54 +0000)
When destroying a new-style Element, reuse the delete_facet method
instead of deleting keys from the origin. Within the delete_facet
method, make sure to delete the corresponding key from the facethash
too.

mudpy/misc.py

index 7478f3f..c3e1940 100644 (file)
@@ -91,8 +91,8 @@ class Element:
         if self.old_style:
             del self.origin.data[self.key]
         else:
-            for facet in self.facethash:
-                del self.origin.data[".".join((self.key, facet))]
+            for facet in dict(self.facethash):
+                self.remove_facet(facet)
         del self.universe.categories[self.category][self.subkey]
         del self.universe.contents[self.key]
         del self
@@ -113,9 +113,13 @@ class Element:
 
     def remove_facet(self, facet):
         """Remove a facet from the element."""
-        if self.has_facet(facet):
-            del(self.origin.data[self.key][facet])
-            self.origin.modified = True
+        if self.old_style and self.has_facet(facet):
+            del self.origin.data[self.key][facet]
+        elif ".".join((self.key, facet)) in self.origin.data:
+            del self.origin.data[".".join((self.key, facet))]
+        if facet in self.facethash:
+            del self.facethash[facet]
+        self.origin.modified = True
 
     def ancestry(self):
         """Return a list of the element's inheritance lineage."""