local variable 'keypair' referenced before assignment

Bug #1299126 reported by Florent Flament
14
This bug affects 2 people
Affects Status Importance Assigned to Milestone
OpenStack Dashboard (Horizon)
Fix Released
Medium
Ana Krivokapić

Bug Description

When a user that isn't allowed to create a keypair tries to create one through the Horizon dashboard, a back trace is displayed instead of the usual nice error message.

Details:

Environment:

Request Method: GET
Request URL: http://localhost:8080/project/access_and_security/keypairs/az/generate/

Django Version: 1.6.2
Python Version: 2.7.3
Installed Applications:
['openstack_dashboard.dashboards.project',
 'openstack_dashboard.dashboards.admin',
 'openstack_dashboard.dashboards.settings',
 'openstack_dashboard',
 'django.contrib.contenttypes',
 'django.contrib.auth',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.humanize',
 'compressor',
 'horizon',
 'openstack_auth']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'horizon.middleware.HorizonMiddleware',
 'django.middleware.doc.XViewMiddleware',
 'django.middleware.locale.LocaleMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware')

Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
  114. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/opt/stack/horizon/openstack_dashboard/wsgi/../../horizon/decorators.py" in dec
  38. return view_func(request, *args, **kwargs)
File "/opt/stack/horizon/openstack_dashboard/wsgi/../../horizon/decorators.py" in dec
  54. return view_func(request, *args, **kwargs)
File "/opt/stack/horizon/openstack_dashboard/wsgi/../../horizon/decorators.py" in dec
  38. return view_func(request, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/views/generic/base.py" in view
  69. return self.dispatch(request, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/views/generic/base.py" in dispatch
  87. return handler(request, *args, **kwargs)
File "/opt/stack/horizon/openstack_dashboard/wsgi/../../openstack_dashboard/dashboards/project/access_and_security/keypairs/views.py" in get
  78. 'attachment; filename=%s.pem' % slugify(keypair.name)

Exception Type: UnboundLocalError at /project/access_and_security/keypairs/az/generate/
Exception Value: local variable 'keypair' referenced before assignment

Revision history for this message
Julie Pichon (jpichon) wrote :

I think this will be partially fixed with the Nova RBAC patch in Icehouse ( https://blueprints.launchpad.net/horizon/+spec/compute-rbac ), the action button won't be shown if the action isn't allowed.

However we should still fail more gracefully in the meantime, the exception message indicates an initialisation error in the code. We should make sure the redirect happens in the exception, I think https://github.com/openstack/horizon/blob/1fdac75d4f/openstack_dashboard/dashboards/project/access_and_security/keypairs/views.py#L70

Changed in horizon:
status: New → Triaged
importance: Undecided → Medium
milestone: none → juno-1
tags: added: icehouse-backport-potential
Changed in horizon:
assignee: nobody → Ana Krivokapić (akrivoka)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to horizon (master)

Fix proposed to branch: master
Review: https://review.openstack.org/84109

Changed in horizon:
status: Triaged → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to horizon (master)

Reviewed: https://review.openstack.org/84109
Committed: https://git.openstack.org/cgit/openstack/horizon/commit/?id=3a8409859fbd8c23289708980964394d2c34cb54
Submitter: Jenkins
Branch: master

commit 3a8409859fbd8c23289708980964394d2c34cb54
Author: Ana Krivokapic <email address hidden>
Date: Mon Mar 31 13:39:45 2014 +0200

    Move `Forbidden` exceptions to `RECOVERABLE` group

    Previously the Forbidden exceptions raised by clients were classified
    as UNAUTHORIZED. This classification is not entirely correct, as
    the UNAUTHORIZED group of exceptions implies that the user should be
    logged out and forced to log in again. This, however, is not the case
    with Forbidden exceptions. Thus, it is more appropriate to place the
    Forbidden exceptions into the RECOVERABLE group.

    Change-Id: I7e52ed72d66e9d0496bc07036e48c968e7a66c2e
    Closes-bug: #1299126

Changed in horizon:
status: In Progress → Fix Committed
Thierry Carrez (ttx)
Changed in horizon:
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in horizon:
milestone: juno-1 → 2014.2
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.