Skip to content

Commit

Permalink
self._raw.get('results', []) returns None, not [] which breaks
Browse files Browse the repository at this point in the history
when we try to iterate it. writing it like this will ensure that the user
will receive an empty response (empty Aggs list) which will not raise
TypeError: 'NoneType' object is not iterable
  • Loading branch information
shlomiku committed Jul 27, 2020
1 parent 0605371 commit d9c6b0d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion alpaca_trade_api/polygon/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,14 @@ def __init__(self, raw):
])

def _raw_results(self):
return self._raw.get('results', [])
results = self._raw.get('results')
if not results:
# this is not very pythonic but it's written like this because
# the raw response for empty aggs was None, and this:
# self._raw.get('results', []) returns None, not [] which breaks
# when we try to iterate it.
return []
return results

def rename_keys(self):
colmap = {
Expand Down

0 comments on commit d9c6b0d

Please sign in to comment.