You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was using the wrong Type, but still HashType raises an error on to_native(), because it expects a Class attribute LENGTH. This works for SHA and the derived hashtypes because they have a length, but if you use HashType by itself, you also need to set LENGTH or it will die on to_native(). Note: it validates fine without LENGTH.
class HashType(StringType):
MESSAGES = {
'hash_length': _("Hash value is wrong length."),
'hash_hex': _("Hash value is not hexadecimal."),
}
def _mock(self, context=None):
return random_string(self.LENGTH, string.hexdigits)
def to_native(self, value, context=None):
value = super(HashType, self).to_native(value, context)
if len(value) != self.LENGTH:
raise ValidationError(self.messages['hash_length'])
try:
int(value, 16)
except ValueError:
raise ConversionError(self.messages['hash_hex'])
return value
The text was updated successfully, but these errors were encountered:
I was using the wrong Type, but still HashType raises an error on to_native(), because it expects a Class attribute LENGTH. This works for SHA and the derived hashtypes because they have a length, but if you use HashType by itself, you also need to set LENGTH or it will die on to_native(). Note: it validates fine without LENGTH.
The text was updated successfully, but these errors were encountered: