OpenUpSA/wazimap-ng

MetricsSerializer breaks for missing subindicator

Opened this issue · 0 comments

In MetricsSerializer there is an error when the Subindicator is not available for a specific geography:

indicator_data = IndicatorData.objects.filter(indicator__profilekeymetrics=profile_key_metric, geography=geography)
if indicator_data.count() > 0:
subindicator = get_subindicator(profile_key_metric)
data = indicator_data.first().data # TODO what to do with multiple results
return data["subindicators"][subindicator]

If subindicator is not available this will result in a 500 server error. With KeyError

There are several things that need to happen here:

  • create a test for this edge case
  • use .get instead of []
  • return a default value if the subindicator is missing: N/A

https://trello.com/c/svbZLvHv/650-absolute-value-calculator-bug