Fix KeyError in router:AddInterface error handle

Under some circumstances the exception handling on adding an interface
to a router will produce a KeyError.

The exception happens in
openstack_dashboard/dashboards/project/routers/ports/forms.py in
AddInterface.populate_subnet_id_choices.

In the exception handling code, a reverse() is called an argument of
request.REQUEST['router_id'] which doesn't always exist.

The fix is quite simple: try to look for it in the initial form data as
well, and if 'router_id' is in neither location, fall-back to the index
page.

Change-Id: I74eaf8cd024d2929fed3d4e00b644e5850e2d5b3
Closes-Bug: 1304533
This commit is contained in:
woodm1979 2014-04-08 10:38:52 -06:00
parent af87ddc473
commit 301569b81d
1 changed files with 6 additions and 2 deletions

View File

@ -56,8 +56,12 @@ class AddInterface(forms.SelfHandlingForm):
msg = _('Failed to get network list %s') % e.message
LOG.info(msg)
messages.error(request, msg)
redirect = reverse(self.failure_url,
args=[request.REQUEST['router_id']])
router_id = request.REQUEST.get('router_id',
self.initial.get('router_id'))
if router_id:
redirect = reverse(self.failure_url, args=[router_id])
else:
redirect = reverse('horizon:project:routers:index')
exceptions.handle(request, msg, redirect=redirect)
return