mirror of
https://github.com/evennia/evennia.git
synced 2026-03-16 21:06:30 +01:00
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:
commit
c497fd7513
2 changed files with 19 additions and 0 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue