From cd90ad2497f88b4dbbe4eb126572295be79b8a52 Mon Sep 17 00:00:00 2001 From: Ryan Petrello Date: Fri, 5 Apr 2019 14:02:19 -0400 Subject: [PATCH] fix a small bug related to failed inventory counts in the dashboard API --- awx/api/views/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/awx/api/views/__init__.py b/awx/api/views/__init__.py index b92e95b8a8..009cf9649f 100644 --- a/awx/api/views/__init__.py +++ b/awx/api/views/__init__.py @@ -179,7 +179,8 @@ class DashboardView(APIView): user_inventory = get_user_queryset(request.user, models.Inventory) inventory_with_failed_hosts = user_inventory.filter(hosts_with_active_failures__gt=0) user_inventory_external = user_inventory.filter(has_inventory_sources=True) - failed_inventory = user_inventory.aggregate(Sum('inventory_sources_with_failures'))['inventory_sources_with_failures__sum'] + # it there are *zero* inventories, this aggregrate query will be None, fall back to 0 + failed_inventory = user_inventory.aggregate(Sum('inventory_sources_with_failures'))['inventory_sources_with_failures__sum'] or 0 data['inventories'] = {'url': reverse('api:inventory_list', request=request), 'total': user_inventory.count(), 'total_with_inventory_source': user_inventory_external.count(),