From 1ad91fed2ccbb3dd83d8f7d6725ed9c4441f390b Mon Sep 17 00:00:00 2001 From: Griatch Date: Sun, 11 Aug 2024 12:25:56 +0200 Subject: [PATCH] Log more useful error message if using ObjectDB root instead of typeclass. Resolve #3556 --- CHANGELOG.md | 6 ++++-- evennia/objects/models.py | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab94b2d08f..49cd68462c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,12 +2,14 @@ ## Main branch -[Docs][issue3591]: Fix of NPC reaction tutorial code (Griatch) -[Docs][issue3590]: Make `examine` command properly show `strattr` type +[Fix][issue3556]: Better error if trying to treat ObjectDB as a typeclass (Griatch) +[Fix][issue3590]: Make `examine` command properly show `strattr` type Attribute values (Griatch) +[Docs][issue3591]: Fix of NPC reaction tutorial code (Griatch) [issue3591]: https://github.com/evennia/evennia/issues/3591 [issue3590]: https://github.com/evennia/evennia/issues/3590 +[issue3556]: https://github.com/evennia/evennia/issues/3556 ## Evennia 4.3.0 diff --git a/evennia/objects/models.py b/evennia/objects/models.py index 5d4bfd4acf..544f33fd2d 100644 --- a/evennia/objects/models.py +++ b/evennia/objects/models.py @@ -20,7 +20,6 @@ from django.conf import settings from django.core.exceptions import ObjectDoesNotExist from django.core.validators import validate_comma_separated_integer_list from django.db import models - from evennia.objects.manager import ObjectDBManager from evennia.typeclasses.models import TypedObject from evennia.utils import logger @@ -71,8 +70,18 @@ class ContentsHandler: objects = self.load() self._pkcache = {obj.pk: True for obj in objects} for obj in objects: - for ctype in obj._content_types: - self._typecache[ctype][obj.pk] = True + try: + ctypes = obj._content_types + except AttributeError: + logger.log_err( + f"Object {obj} has no `_content_types` property. Skipping content-cache setup. " + "This error suggests it is not a valid Evennia Typeclass but maybe a root model " + "like `ObjectDB`. Investigate the `db_typeclass_path` of the object and make sure " + "it points to a proper, existing Typeclass." + ) + else: + for ctype in obj._content_types: + self._typecache[ctype][obj.pk] = True def get(self, exclude=None, content_type=None): """