Skip to content

Commit

Permalink
Make aliased get_stats pass None on error
Browse files Browse the repository at this point in the history
  • Loading branch information
meg-codes committed May 23, 2019
1 parent 1b711ff commit 7769a67
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
9 changes: 5 additions & 4 deletions parasolr/query/aliased_queryset.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,11 @@ def get_stats(self) -> Dict[str, Dict]:
"""Extend :meth:`parasolr.query.queryset.SolrQuerySet.get_stats` to
return return aliased field names for field_list keys."""
stats = super().get_stats()
stats['stats_fields'] = {
self.reverse_aliases.get(field, field): val
for field, val in stats['stats_fields'].items()
}
if stats:
stats['stats_fields'] = {
self.reverse_aliases.get(field, field): val
for field, val in stats['stats_fields'].items()
}
return stats

# NOTE: may want to do the same for highlighting also eventually,
Expand Down
5 changes: 5 additions & 0 deletions parasolr/query/tests/test_aliased_queryset.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ def test_get_stats(self, mock_get_stats):
assert 'start_i' in stats['stats_fields']
assert stats['stats_fields']['start_i'] \
== sample_stats['stats_fields']['start_i']
# ensure that if get_stats returns None on error,
# we don't have a key error when try to realias fields
mock_get_stats.return_value = None
assert self.mysqs.get_stats() is None




0 comments on commit 7769a67

Please sign in to comment.