Merge pull request #3836 from count-infinity/bug-3822-create-obj-none-key

Fix error when creating object with None key
This commit is contained in:
Griatch 2025-11-19 18:38:17 +01:00 committed by GitHub
commit c497fd7513
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
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)