| Summary: | catch IndexError errors for get_dict_value | ||
|---|---|---|---|
| Product: | [Build System, Metadata & Runtime] Toaster | Reporter: | David Reyna <david.reyna> |
| Component: | toaster | Assignee: | 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) | |
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,
commit 4707c7c3eebdb15d5560af6c2e6cee68f85e0a5f Verified in ea90bd054c449a8e19c474c8bfa8c289f692c33f. |
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 ''