From e3ddbf08cf1558fe9a354fa647dd4dfc240bc929 Mon Sep 17 00:00:00 2001 From: Griatch Date: Sat, 6 Apr 2024 22:42:01 +0200 Subject: [PATCH] Fix Component contrib issue with corrected AttributeProperty --- .../contrib/base_systems/components/component.py | 16 ++++++++++++++++ .../contrib/base_systems/components/dbfield.py | 3 ++- evennia/contrib/base_systems/components/tests.py | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/evennia/contrib/base_systems/components/component.py b/evennia/contrib/base_systems/components/component.py index 48c7dfa738..6397b77a07 100644 --- a/evennia/contrib/base_systems/components/component.py +++ b/evennia/contrib/base_systems/components/component.py @@ -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): """ diff --git a/evennia/contrib/base_systems/components/dbfield.py b/evennia/contrib/base_systems/components/dbfield.py index 4b9c6d4fa8..67f812b484 100644 --- a/evennia/contrib/base_systems/components/dbfield.py +++ b/evennia/contrib/base_systems/components/dbfield.py @@ -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 diff --git a/evennia/contrib/base_systems/components/tests.py b/evennia/contrib/base_systems/components/tests.py index b11ce68937..75e169b825 100644 --- a/evennia/contrib/base_systems/components/tests.py +++ b/evennia/contrib/base_systems/components/tests.py @@ -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")