From 3fef2b10f483caf183dd7abbc5e9f6b7188a0082 Mon Sep 17 00:00:00 2001 From: David Lyle Date: Mon, 21 Oct 2013 13:15:33 -0600 Subject: [PATCH] Fixing possible exception on tables in tabs When a filter action for instance goes to the server via POST, an 'action' field is not necessarily present in the POST. This results in an uncaught exception. Fixing this so if 'action' is not present falling back to old behavior. Closes-Bug: #1242846 Change-Id: I693fc8174f891cb0e281e5c2810f455b368802ca --- horizon/tabs/views.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/horizon/tabs/views.py b/horizon/tabs/views.py index e959a267b3..92b3b6cf46 100644 --- a/horizon/tabs/views.py +++ b/horizon/tabs/views.py @@ -138,14 +138,16 @@ class TabbedTableView(tables.MultiTableMixin, TabView): def post(self, request, *args, **kwargs): # Direct POST to it's appropriate tab - targetslug = request.POST['action'].split('__')[0] - tabs = self.get_tabs(self.request, **self.kwargs).get_tabs() - matches = [tab for tab in tabs if tab.slug == targetslug] - if matches: - # Call POST on first match only. There shouldn't be a case where - # multiple tabs have the same slug and processing the request twice - # could lead to unpredictable behavior. - matches[0].post(request, *args, **kwargs) + # Note some table actions like filter do not have an 'action' + if 'action' in request.POST: + targetslug = request.POST['action'].split('__')[0] + tabs = self.get_tabs(self.request, **self.kwargs).get_tabs() + matches = [tab for tab in tabs if tab.slug == targetslug] + if matches: + # Call POST on first match only. There shouldn't be a case + # where multiple tabs have the same slug and processing the + # request twice could lead to unpredictable behavior. + matches[0].post(request, *args, **kwargs) # GET and POST handling are the same return self.get(request, *args, **kwargs)