mirror of
https://github.com/evennia/evennia.git
synced 2025-10-29 19:35:56 +00:00
Remove check of datestring if trying to load an replaced class from an Attribute
This commit is contained in:
parent
59e2e136e0
commit
4f8d70118e
@ -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"))]
|
||||
|
||||
@ -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):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user