From 2ea0d77eb2349a2946c0475923441701e6513adc Mon Sep 17 00:00:00 2001 From: Hugo LEVY-FALK Date: Fri, 11 Jan 2019 14:02:32 +0100 Subject: [PATCH] Fix error message when failing to decode an aes_key. --- re2o/aes_field.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/re2o/aes_field.py b/re2o/aes_field.py index 5f50ddd2..eeab5e12 100644 --- a/re2o/aes_field.py +++ b/re2o/aes_field.py @@ -82,16 +82,22 @@ class AESEncryptedField(models.CharField): return None try: return decrypt(settings.AES_KEY, binascii.a2b_base64(value)).decode('utf-8') - except Exception as e: - raise ValueError(value) + except UnicodeDecodeError as e: + raise ValueError( + "Could not decode your field %s, your settings.AES_KEY " + "is probably wrong." % self.name + ) def from_db_value(self, value, *args, **kwargs): if value is None: return value try: return decrypt(settings.AES_KEY, binascii.a2b_base64(value)).decode('utf-8') - except Exception as e: - raise ValueError(value) + except UnicodeDecodeError as e: + raise ValueError( + "Could not decode your field %s, your settings.AES_KEY " + "is probably wrong." % self.name + ) def get_prep_value(self, value): if value is None: