Prevent KeyError getting value of optional data

Bug #2066115 reported by Nguyen Luu Hoang Minh
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Dashboard (Horizon)
In Progress
Undecided
Nguyen Luu Hoang Minh

Bug Description

Problem: Some of optional data is retrieved in this way:
        backup_name = data['backup_name'] or None
        volume_id = data['volume_id'] or None

etc...

When the key does not exist, KeyError will be raised.
Moreover, or None here is meaningless.

Solution:
Change to
        backup_name = data.get('backup_name')
        volume_id = data.get('volume_id')

Changed in horizon:
assignee: nobody → Nguyen Luu Hoang Minh (minhnlh2)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to horizon (master)

Fix proposed to branch: master
Review: https://review.opendev.org/c/openstack/horizon/+/919430

Changed in horizon:
status: New → In Progress
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

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