From a98bf9d7a5a3eefd39e47e394495605c507b2ab9 Mon Sep 17 00:00:00 2001 From: Ryan Castner Date: Tue, 2 Jan 2018 12:28:02 -0500 Subject: [PATCH] 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. --- src/auditlog/models.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/auditlog/models.py b/src/auditlog/models.py index f753ad5..5f4ebed 100644 --- a/src/auditlog/models.py +++ b/src/auditlog/models.py @@ -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)