diff --git a/server/atheneum/service/transformation_service.py b/server/atheneum/service/transformation_service.py index 774c0ad..20eaee6 100644 --- a/server/atheneum/service/transformation_service.py +++ b/server/atheneum/service/transformation_service.py @@ -77,7 +77,7 @@ def register_transformer( if model_name not in _model_transformers: _model_transformers[model_name] = model_serializer else: - raise ValueError( + raise KeyError( ' '.join([ 'A transformer for type "{}" already exists with class "{}".', 'Cannot register a new transformer with class "{}"' @@ -100,12 +100,12 @@ def serialize_model(model_obj: db.Model, def deserialize_model( - model_type: str, + model_type: Type[db.Model], json_model_object: dict, options: Optional[List[str]] = None) -> db.Model: """Lookup a Model and hand it off to the deserializer.""" try: - transformer = _model_transformers[model_type] + transformer = _model_transformers[model_type.__name__] return transformer( transformer.type()).deserialize(json_model_object, options) except KeyError: diff --git a/server/tests/service/test_transformation_service.py b/server/tests/service/test_transformation_service.py index 297cc17..4452733 100644 --- a/server/tests/service/test_transformation_service.py +++ b/server/tests/service/test_transformation_service.py @@ -24,7 +24,7 @@ def test_deserialize_model(): user_token_json = { 'token': 'test' } - result = deserialize_model('UserToken', user_token_json) + result = deserialize_model(UserToken, user_token_json) assert result is not None assert result.token == 'test' @@ -40,7 +40,7 @@ def test_registering_two_transformers_of_the_same_type(): pass error = None - with pytest.raises(ValueError) as e_info: + with pytest.raises(KeyError) as e_info: error = e_info register_transformer(BadTransformer)