Bug 6067

Summary: catch IndexError errors for get_dict_value
Product: [Build System, Metadata & Runtime] Toaster Reporter: David Reyna <david.reyna>
Component: toasterAssignee: David Reyna <david.reyna>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: Medium CC: alexandru.damian, belen.barros.pena, cristiana.voicu, jessica.zhang, Yuan.Sun2
Version: 1.6   
Target Milestone: 1.6 M5   
Hardware: x86   
OS: Multiple   
Whiteboard:
OS type for building Yocto: --- Type of Regression: ---
Verified: Documentation change: No (bug/feature does not impact docs)

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.