Fix Component contrib issue with corrected AttributeProperty

This commit is contained in:
Griatch 2024-04-06 22:42:01 +02:00
parent b8e37f9cf2
commit e3ddbf08cf
3 changed files with 19 additions and 2 deletions

View file

@ -155,6 +155,22 @@ class Component(metaclass=BaseComponent):
"""
return self.host.attributes
@property
def pk(self):
"""
Shortcut property returning the host's primary key.
Returns:
int: The Host's primary key.
Notes:
This is requried to allow AttributeProperties to correctly update `_SaverMutable` data
(like lists) in-place (since the DBField sits on the Component which doesn't itself
have a primary key, this save operation would otherwise fail).
"""
return self.host.pk
@property
def nattributes(self):
"""

View file

@ -6,7 +6,8 @@ This file contains the Descriptors used to set Fields in Components
import typing
from evennia.typeclasses.attributes import AttributeProperty, NAttributeProperty
from evennia.typeclasses.attributes import (AttributeProperty,
NAttributeProperty)
if typing.TYPE_CHECKING:
from .components import Component

View file

@ -268,7 +268,7 @@ class TestComponents(EvenniaTest):
def test_mutables_are_not_shared_when_autocreate(self):
self.char1.test_a.my_list.append(1)
self.assertNotEqual(self.char1.test_a.my_list, self.char2.test_a.my_list)
self.assertNotEqual(id(self.char1.test_a.my_list), id(self.char2.test_a.my_list))
def test_replacing_class_component_slot_with_runtime_component(self):
self.char1.components.add_default("replacement_inherited_test_a")