diff --git a/reports/nova_usage_audit.py b/reports/nova_usage_audit.py index a8f813d..dd58049 100644 --- a/reports/nova_usage_audit.py +++ b/reports/nova_usage_audit.py @@ -95,10 +95,7 @@ def _get_exists(beginning, ending): def cell_and_compute(instance, launched_at): usage = InstanceUsage.find(instance, launched_at)[0] - try: - deployment = usage.latest_deployment_for_request_id() - except IndexError: - deployment = None + deployment = usage.latest_deployment_for_request_id() cell = (deployment and deployment.name) or '-' compute = usage.host() or '-' return cell, compute diff --git a/stacktach/models.py b/stacktach/models.py index d42a5d4..ee1b187 100644 --- a/stacktach/models.py +++ b/stacktach/models.py @@ -185,8 +185,10 @@ class InstanceUsage(models.Model): return raw and raw.deployment def latest_raw_for_request_id(self): - return self.request_id and RawData.objects.filter( - request_id=self.request_id).order_by('-id')[0] + raw = [] + if self.request_id: + raw = RawData.objects.filter(request_id=self.request_id).order_by('-id') + return (len(raw) > 0 and raw[0]) or None def host(self): raw = self.latest_raw_for_request_id()