Remove check of datestring if trying to load an replaced class from an Attribute

This commit is contained in:
Griatch 2017-09-17 14:02:14 +02:00
parent 59e2e136e0
commit 4f8d70118e
2 changed files with 14 additions and 10 deletions

View file

@ -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 # 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 # can convert old to new when retrieving them. This is a list of tuples
# (old_natural_key, new_natural_key). Note that Django ContentTypes' # (old_natural_key, new_natural_key). Note that Django ContentTypes'
# natural_keys are themselves tuples (appname, modelname). If new_natural_key # natural_keys are themselves tuples (appname, modelname). Creation-dates will
# does not exist, `None` will be returned and stored back as if no replacement # not be checked for models specified here. If new_natural_key does not exist,
# was set. # `None` will be returned and stored back as if no replacement was set.
ATTRIBUTE_STORED_MODEL_RENAME = [ ATTRIBUTE_STORED_MODEL_RENAME = [
((u"players", u"playerdb"), (u"accounts", u"accountdb")), ((u"players", u"playerdb"), (u"accounts", u"accountdb")),
((u"typeclasses", u"defaultplayer"), (u"typeclasses", u"defaultaccount"))] ((u"typeclasses", u"defaultplayer"), (u"typeclasses", u"defaultaccount"))]

View file

@ -67,6 +67,7 @@ _GA = object.__getattribute__
_SA = object.__setattr__ _SA = object.__setattr__
_FROM_MODEL_MAP = None _FROM_MODEL_MAP = None
_TO_MODEL_MAP = None _TO_MODEL_MAP = None
_IGNORE_DATETIME_MODELS = None
_SESSION_HANDLER = None _SESSION_HANDLER = None
@ -110,7 +111,7 @@ def _TO_DATESTRING(obj):
def _init_globals(): def _init_globals():
"""Lazy importing to avoid circular import issues""" """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: if not _FROM_MODEL_MAP:
_FROM_MODEL_MAP = defaultdict(str) _FROM_MODEL_MAP = defaultdict(str)
_FROM_MODEL_MAP.update(dict((c.model, c.natural_key()) for c in ContentType.objects.all())) _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 from django.conf import settings
_TO_MODEL_MAP = defaultdict(str) _TO_MODEL_MAP = defaultdict(str)
_TO_MODEL_MAP.update(dict((c.natural_key(), c.model_class()) for c in ContentType.objects.all())) _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: for src_key, dst_key in settings.ATTRIBUTE_STORED_MODEL_RENAME:
_TO_MODEL_MAP[src_key] = _TO_MODEL_MAP.get(dst_key, None) _TO_MODEL_MAP[src_key] = _TO_MODEL_MAP.get(dst_key, None)
# handle old player models by converting them to accounts _IGNORE_DATETIME_MODELS.append(src_key)
_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")]
if not _SESSION_HANDLER: if not _SESSION_HANDLER:
from evennia.server.sessionhandler import SESSION_HANDLER as _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 # this happens if item is already an obj
return item return item
return None return None
# even if we got back a match, check the sanity of the date (some if item[1] in _IGNORE_DATETIME_MODELS:
# databases may 're-use' the id) # if we are replacing models we ignore the datatime
return _TO_DATESTRING(obj) == item[2] and obj or None 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): def pack_session(item):