Skip to content
This repository has been archived by the owner on Mar 22, 2018. It is now read-only.

Commit

Permalink
bug: Fix double encoding issue in storage responses. (#13)
Browse files Browse the repository at this point in the history
* bug: Fix double encoding issue in storage responses.

This change updates the on_* methods for the storage service to return
dictionaries rather than json strings. This lets then service framework
handle encoding/decoding and avoid double encoding issues where results
were becoming a proper response with a result being a list of json
strings or str. Now proper responses will have a result as a list of
proper types (the most common being dict) or a specific type.

* fixup! bug: Fix double encoding issue in storage responses.
  • Loading branch information
ashcrow authored and mbarnes committed Oct 3, 2016
1 parent ec5c52b commit cd0ca30
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/commissaire_service/storage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ def on_save(self, message, model_type_name, model_json_data):
:type model_type_name: str
:param model_json_data: JSON representation of a model
:type model_json_data: str
:returns: full JSON representation of the model
:rtype: str
:returns: full dict representation of the model
:rtype: dict
"""
model_instance = self._build_model(model_type_name, model_json_data)
saved_model_instance = self._manager.save(model_instance)
return saved_model_instance.to_json()
return saved_model_instance.to_dict()

def on_get(self, message, model_type_name, model_json_data):
"""
Expand All @@ -155,12 +155,12 @@ def on_get(self, message, model_type_name, model_json_data):
:type model_type_name: str
:param model_json_data: JSON identification of a model
:type model_json_data: str
:returns: full JSON representation of the model
:rtype: str
:returns: full dict representation of the model
:rtype: dict
"""
model_instance = self._build_model(model_type_name, model_json_data)
full_model_instance = self._manager.get(model_instance)
return full_model_instance.to_json()
return full_model_instance.to_dict()

def on_delete(self, message, model_type_name, model_json_data):
"""
Expand Down Expand Up @@ -189,12 +189,12 @@ def on_list(self, message, model_type_name):
:type message: kombu.message.Message
:param model_type_name: Model type for the JSON data
:type model_type_name: str
:returns: a list of model representations as JSON strings
:returns: a list of model representations as dicts
:rtype: list
"""
model_type = self._model_types[model_type_name]
model_list = self._manager.list(model_type.new())
return [model_instance.to_json() for model_instance in model_list]
return [model_instance.to_dict() for model_instance in model_list]


def main(): # pragma: no cover
Expand Down

0 comments on commit cd0ca30

Please sign in to comment.