Bug 6067 - catch IndexError errors for get_dict_value
Summary: catch IndexError errors for get_dict_value
Status: VERIFIED FIXED
Alias: None
Product: Toaster
Classification: Build System, Metadata & Runtime
Component: toaster (show other bugs)
Version: 1.6
Hardware: x86 Multiple
: Medium normal
Target Milestone: 1.6 M5
Assignee: David Reyna
QA Contact:
URL:
Whiteboard:
Depends on:
Blocks:
 
Reported: 2014-03-29 05:08 UTC by David Reyna
Modified: 2014-04-17 03:28 UTC (History)
5 users (show)

See Also:
OS type for building Yocto: ---
Type of Regression: ---
Verified:
Documentation change: No (bug/feature does not impact docs)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Reyna 2014-03-29 05:08:47 UTC
In broken builds, you can sometimes get an IndexError errors for the filter "get_dict_value", so that needs to by handled.

Here is the fix: 

@register.filter
def get_dict_value(dictionary, key):
    """ return the value of a dictionary key
    """
    try:
        return dictionary[key]
    except (KeyError, IndexError):
        return ''
Comment 1 David Reyna 2014-04-02 22:07:56 UTC
I believe that error I observed happened when then dictionary object passed to this filter did not actually exist. This normally be impossible but for the fact that in my instance the version of the view class was older that the template that called this filter, so the dictionary object was not present in the context.

For a reproducer one could comment out the 'fstypes' context entry in the "builds" class, and the bring up the all builds page in Toaster, thus simulating the illegal condition.

def builds(request):
...
                'objectname' : "builds",
 #               'fstypes' : fstypes_map,
                'search_term' : search_term,
Comment 2 David Reyna 2014-04-09 23:19:57 UTC
commit 4707c7c3eebdb15d5560af6c2e6cee68f85e0a5f
Comment 3 Yuan Sun 2014-04-17 03:28:53 UTC
Verified in ea90bd054c449a8e19c474c8bfa8c289f692c33f.