Fix error when creating object with None key

This commit is contained in:
Count Infinity 2025-11-11 21:32:49 -07:00
parent 3cd5be6e82
commit 8e607f7185
2 changed files with 19 additions and 0 deletions

View file

@ -685,6 +685,11 @@ class ObjectDBManager(TypedObjectManager):
"or the setting is malformed."
)
# db_key has NOT NULL constraint, convert None to empty string.
# at_first_save() will convert empty string to #dbref
if key is None:
key = ""
# create new instance
new_object = typeclass(
db_key=key,

View file

@ -244,6 +244,20 @@ class DefaultObjectTest(BaseEvenniaTest):
class TestObjectManager(BaseEvenniaTest):
"Test object manager methods"
def test_create_object_with_none_key(self):
"""Test that create_object() handles key=None and key="" correctly."""
# Test with key=None - should convert to "" and then to #dbref
obj_none = ObjectDB.objects.create_object(key=None, location=self.room1)
self.assertIsNotNone(obj_none)
self.assertEqual(obj_none.key, f"#{obj_none.id}")
obj_none.delete()
# Test with key="" - should convert to #dbref
obj_empty = ObjectDB.objects.create_object(key="", location=self.room1)
self.assertIsNotNone(obj_empty)
self.assertEqual(obj_empty.key, f"#{obj_empty.id}")
obj_empty.delete()
def test_get_object_with_account(self):
query = ObjectDB.objects.get_object_with_account("TestAccount").first()
self.assertEqual(query, self.char1)