mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Improve long integer type validation
Passing a number of "long" type to IPA Int parameter invokes user-unfriendly error message about incompatible types. This patch improves Int parameter with user understandable message along with maximum value he can pass. https://fedorahosted.org/freeipa/ticket/1346
This commit is contained in:
@@ -1066,6 +1066,30 @@ class Int(Number):
|
||||
maxvalue=self.maxvalue,
|
||||
)
|
||||
|
||||
def _validate_scalar(self, value, index=None):
|
||||
if type(value) is long:
|
||||
# too big number for int type to hold
|
||||
if self.maxvalue is not None:
|
||||
raise ValidationError(
|
||||
name=self.name,
|
||||
value=value,
|
||||
index=index,
|
||||
error=_('can be at most %(maxvalue)d') % dict(
|
||||
maxvalue=self.maxvalue,
|
||||
)
|
||||
)
|
||||
else:
|
||||
raise ValidationError(
|
||||
name=self.name,
|
||||
value=value,
|
||||
index=index,
|
||||
error=_('can be at most %(maxvalue)d') % dict(
|
||||
maxvalue=MAXINT,
|
||||
)
|
||||
)
|
||||
super(Int, self)._validate_scalar(value, index)
|
||||
|
||||
|
||||
class Float(Number):
|
||||
"""
|
||||
A parameter for floating-point values (stored in the ``float`` type).
|
||||
|
||||
Reference in New Issue
Block a user