From 4f8d70118e460ec0fb5d11948da47212d1466e58 Mon Sep 17 00:00:00 2001 From: Griatch Date: Sun, 17 Sep 2017 14:02:14 +0200 Subject: [PATCH] Remove check of datestring if trying to load an replaced class from an Attribute --- evennia/settings_default.py | 6 +++--- evennia/utils/dbserialize.py | 18 +++++++++++------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/evennia/settings_default.py b/evennia/settings_default.py index 528fcafac4..79ad2f941f 100644 --- a/evennia/settings_default.py +++ b/evennia/settings_default.py @@ -255,9 +255,9 @@ CONN_MAX_AGE = 3600 * 7 # is, there is a 1:1 pk mapping between the old and the new), the unserializer # can convert old to new when retrieving them. This is a list of tuples # (old_natural_key, new_natural_key). Note that Django ContentTypes' -# natural_keys are themselves tuples (appname, modelname). If new_natural_key -# does not exist, `None` will be returned and stored back as if no replacement -# was set. +# natural_keys are themselves tuples (appname, modelname). Creation-dates will +# not be checked for models specified here. If new_natural_key does not exist, +# `None` will be returned and stored back as if no replacement was set. ATTRIBUTE_STORED_MODEL_RENAME = [ ((u"players", u"playerdb"), (u"accounts", u"accountdb")), ((u"typeclasses", u"defaultplayer"), (u"typeclasses", u"defaultaccount"))] diff --git a/evennia/utils/dbserialize.py b/evennia/utils/dbserialize.py index 0877636a3c..35fc59f761 100644 --- a/evennia/utils/dbserialize.py +++ b/evennia/utils/dbserialize.py @@ -67,6 +67,7 @@ _GA = object.__getattribute__ _SA = object.__setattr__ _FROM_MODEL_MAP = None _TO_MODEL_MAP = None +_IGNORE_DATETIME_MODELS = None _SESSION_HANDLER = None @@ -110,7 +111,7 @@ def _TO_DATESTRING(obj): def _init_globals(): """Lazy importing to avoid circular import issues""" - global _FROM_MODEL_MAP, _TO_MODEL_MAP, _SESSION_HANDLER + global _FROM_MODEL_MAP, _TO_MODEL_MAP, _SESSION_HANDLER, _IGNORE_DATETIME_MODELS if not _FROM_MODEL_MAP: _FROM_MODEL_MAP = defaultdict(str) _FROM_MODEL_MAP.update(dict((c.model, c.natural_key()) for c in ContentType.objects.all())) @@ -118,11 +119,10 @@ def _init_globals(): from django.conf import settings _TO_MODEL_MAP = defaultdict(str) _TO_MODEL_MAP.update(dict((c.natural_key(), c.model_class()) for c in ContentType.objects.all())) + _IGNORE_DATETIME_MODELS = [] for src_key, dst_key in settings.ATTRIBUTE_STORED_MODEL_RENAME: _TO_MODEL_MAP[src_key] = _TO_MODEL_MAP.get(dst_key, None) - # handle old player models by converting them to accounts - _TO_MODEL_MAP[(u"players", u"playerdb")] = _TO_MODEL_MAP[(u"accounts", u"accountdb")] - _TO_MODEL_MAP[(u"typeclasses", u"defaultplayer")] = _TO_MODEL_MAP[(u"typeclasses", u"defaultaccount")] + _IGNORE_DATETIME_MODELS.append(src_key) if not _SESSION_HANDLER: from evennia.server.sessionhandler import SESSION_HANDLER as _SESSION_HANDLER @@ -402,9 +402,13 @@ def unpack_dbobj(item): # this happens if item is already an obj return item return None - # even if we got back a match, check the sanity of the date (some - # databases may 're-use' the id) - return _TO_DATESTRING(obj) == item[2] and obj or None + if item[1] in _IGNORE_DATETIME_MODELS: + # if we are replacing models we ignore the datatime + return obj + else: + # even if we got back a match, check the sanity of the date (some + # databases may 're-use' the id) + return _TO_DATESTRING(obj) == item[2] and obj or None def pack_session(item):