Skip to content

Commit

Permalink
Fixed issue with dict() method of response object not correctly
Browse files Browse the repository at this point in the history
converting all data into a nested dictionary structure. Occurred
when Array object contained instances with no dict() method (primitives).
  • Loading branch information
jamespeterschinner committed Jan 18, 2018
1 parent 4b27d54 commit b9f6b20
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions async_v20/interface/response.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ujson as json
import logging
from ..definitions.base import Specifier
from ..definitions.base import Specifier, Model, Array
import pandas as pd

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -48,20 +48,20 @@ def dict(self, json=False, datetime_format=None):


def value_to_dict(value):
try:
# If value is an Model object
if isinstance(value, Model):
result = value.dict(json, datetime_format)
except AttributeError:
elif isinstance(value, Array):
try:
result = [obj.dict(json, datetime_format) for obj in value]
except (AttributeError, TypeError):
if json and isinstance(value, Specifier):
# Specifiers need to be strings for JSON
result = str(value)
elif json and isinstance(value, pd.Timestamp):
result = value.json(datetime_format)
else:
result = value
except AttributeError:
result = [obj for obj in value]
elif isinstance(value, Specifier) and json:
# Specifiers need to be strings for JSON
result = str(value)
elif isinstance(value, pd.Timestamp) and json:
result = value.json(datetime_format)
else:
result = value
return result

return {key: value_to_dict(value) for key, value in self.items()}
Expand Down

0 comments on commit b9f6b20

Please sign in to comment.