Log more useful error message if using ObjectDB root instead of typeclass. Resolve #3556

This commit is contained in:
Griatch 2024-08-11 12:25:56 +02:00
parent 7d553125ba
commit 1ad91fed2c
2 changed files with 16 additions and 5 deletions

View file

@ -2,12 +2,14 @@
## Main branch ## Main branch
[Docs][issue3591]: Fix of NPC reaction tutorial code (Griatch) [Fix][issue3556]: Better error if trying to treat ObjectDB as a typeclass (Griatch)
[Docs][issue3590]: Make `examine` command properly show `strattr` type [Fix][issue3590]: Make `examine` command properly show `strattr` type
Attribute values (Griatch) Attribute values (Griatch)
[Docs][issue3591]: Fix of NPC reaction tutorial code (Griatch)
[issue3591]: https://github.com/evennia/evennia/issues/3591 [issue3591]: https://github.com/evennia/evennia/issues/3591
[issue3590]: https://github.com/evennia/evennia/issues/3590 [issue3590]: https://github.com/evennia/evennia/issues/3590
[issue3556]: https://github.com/evennia/evennia/issues/3556
## Evennia 4.3.0 ## Evennia 4.3.0

View file

@ -20,7 +20,6 @@ from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
from django.core.validators import validate_comma_separated_integer_list from django.core.validators import validate_comma_separated_integer_list
from django.db import models from django.db import models
from evennia.objects.manager import ObjectDBManager from evennia.objects.manager import ObjectDBManager
from evennia.typeclasses.models import TypedObject from evennia.typeclasses.models import TypedObject
from evennia.utils import logger from evennia.utils import logger
@ -71,8 +70,18 @@ class ContentsHandler:
objects = self.load() objects = self.load()
self._pkcache = {obj.pk: True for obj in objects} self._pkcache = {obj.pk: True for obj in objects}
for obj in objects: for obj in objects:
for ctype in obj._content_types: try:
self._typecache[ctype][obj.pk] = True 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): def get(self, exclude=None, content_type=None):
""" """