Fix issue with init_evennia_properties.

This commit is contained in:
Owllex 2022-04-14 23:35:04 -07:00
parent ef7280f55a
commit d5c916ecc3
2 changed files with 14 additions and 3 deletions

View file

@ -241,11 +241,17 @@ class TestObjectPropertiesClass(DefaultObject):
testalias = AliasProperty()
testperm = PermissionProperty()
@property
def base_property(self):
self.property_initialized = True
class TestProperties(EvenniaTestCase):
"""
Test Properties.
"""
def setUp(self):
self.obj = create.create_object(TestObjectPropertiesClass, key="testobj")
@ -270,7 +276,7 @@ class TestProperties(EvenniaTestCase):
self.assertFalse(obj.attributes.has("attr3"))
self.assertEqual(obj.attr3, "attr3")
obj.attr3 = "attr3b" # stores it in db!
obj.attr3 = "attr3b" # stores it in db!
self.assertEqual(obj.db.attr3, "attr3b")
self.assertTrue(obj.attributes.has("attr3"))
@ -280,3 +286,7 @@ class TestProperties(EvenniaTestCase):
self.assertTrue(obj.aliases.has("testalias"))
self.assertTrue(obj.permissions.has("testperm"))
# Verify that regular properties do not get fetched in init_evennia_properties,
# only Attribute or TagProperties.
self.assertFalse(hasattr(obj, "property_initialized"))

View file

@ -39,11 +39,12 @@ from django.utils.text import slugify
from evennia.typeclasses.attributes import (
Attribute,
AttributeHandler,
AttributeProperty,
ModelAttributeBackend,
InMemoryAttributeBackend,
)
from evennia.typeclasses.attributes import DbHolder
from evennia.typeclasses.tags import Tag, TagHandler, AliasHandler, PermissionHandler
from evennia.typeclasses.tags import Tag, TagHandler, AliasHandler, PermissionHandler, TagProperty
from evennia.utils.idmapper.models import SharedMemoryModel, SharedMemoryModelBase
from evennia.server.signals import SIGNAL_TYPED_OBJECT_POST_RENAME
@ -331,7 +332,7 @@ class TypedObject(SharedMemoryModel):
by fetching them once.
"""
for propkey, prop in self.__class__.__dict__.items():
if hasattr(prop, "__set_name__"):
if isinstance(prop, (AttributeProperty, TagProperty)):
try:
getattr(self, propkey)
except Exception: