Commit 3443965e authored by chirac's avatar chirac

Merge branch 'fix_aesfield_error' into 'dev'

Fix error message when failing to decode an aes_key.

See merge request federez/re2o!393
parents 88416a28 2ea0d77e
Pipeline #937 canceled with stage
......@@ -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:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment