The previous conditional did not work as expected, when field.choices returns an empty dict the boolean is False and the operator does not shortcircuit as expected. This causes field.base_field.choices to be evaluated which crashes as it does not exist and field.choices was supposed to be the input. The updated version fixes this bug.

This commit is contained in:
Ryan Castner 2018-01-02 12:28:02 -05:00
parent 2105366379
commit a98bf9d7a5

View file

@ -259,8 +259,13 @@ class LogEntry(models.Model):
continue
values_display = []
# handle choices fields and Postgres ArrayField to get human readable version
if field.choices or hasattr(field, 'base_field') and getattr(field.base_field, 'choices', False):
choices_dict = dict(field.choices or field.base_field.choices)
choices_dict = None
if hasattr(field, 'choices'):
choices_dict = dict(field.choices)
elif hasattr(field, 'base_field') and getattr(field.base_field, 'choices', False):
choices_dict = dict(field.base_field.choices)
if choices_dict:
for value in values:
try:
value = ast.literal_eval(value)