models: Stop using globals to get model names in JSON decoding.

This commit is contained in:
Thomas Adamcik 2015-04-08 00:36:03 +02:00
parent 86481b1d50
commit dd270ab87b

View File

@ -282,13 +282,13 @@ def model_json_decoder(dct):
"""
if '__model__' in dct:
models = {c.__name__: c for c in ImmutableObject.__subclasses__()}
model_name = dct.pop('__model__')
cls = globals().get(model_name, None)
if issubclass(cls, ImmutableObject):
if model_name in models:
kwargs = {}
for key, value in dct.items():
kwargs[key] = value
return cls(**kwargs)
return models[model_name](**kwargs)
return dct