Skip to content

Commit

Permalink
fix: handle (and test) reporting with no indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
aaxelb committed Oct 2, 2024
1 parent 79f4cd6 commit cc1e078
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion osf/metrics/reporters/public_item_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,10 @@ def _iter_composite_buckets(search: edsl.Search, composite_agg_name: str):
'''
while True:
_page_response = search.execute(ignore_cache=True)
_agg_result = _page_response.aggregations[composite_agg_name]
try:
_agg_result = _page_response.aggregations[composite_agg_name]
except KeyError:
return # no data; all done
yield from _agg_result.buckets
# update the search for the next page
try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ def busy_month_item2(self, ym_busy):
action_labels=['download'],
)

def test_no_data(self, ym_empty):
_reporter = PublicItemUsageReporter()
_empty = list(_reporter.report(ym_empty))
assert _empty == []

def test_reporter(self, ym_empty, ym_sparse, ym_busy, sparse_month_usage, busy_month_item0, busy_month_item1, busy_month_item2):
_reporter = PublicItemUsageReporter()
_empty = list(_reporter.report(ym_empty))
Expand Down

0 comments on commit cc1e078

Please sign in to comment.