Skip to content

Commit e9d420f

Browse files
committed
raise ValidationError if value has no length
1 parent b241698 commit e9d420f

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

CHANGELOG.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
=====
33

44
* BugFix: recursive field validation
5+
* BugFix: fullCount option now works
6+
* Length validator will raise a ValidationError if value has no length
7+
* users can now specify custon json encoders
58

69
1.2.7
710
=====

pyArango/validation.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ def __init__(self, minLen, maxLen) :
3636
self.maxLen = maxLen
3737

3838
def validate(self, value) :
39-
if self.minLen <= len(value) and len(value) <= self.maxLen :
40-
return True
41-
42-
raise ValidationError("Field must have a length in ['%s';'%s'] got: '%s'" % (self.minLen, self.maxLen, len(value)))
39+
try:
40+
if self.minLen <= len(value) and len(value) <= self.maxLen :
41+
return True
42+
raise ValidationError("Field must have a length in ['%s';'%s'] got: '%s'" % (self.minLen, self.maxLen, len(value)))
43+
except Exception as e:
44+
raise ValidationError("Invalid value: '%s' has no length" % value)
4345

4446
def __str__(self) :
4547
return "%s[%s, %s]" % (self.__class__.__name__, self.minLen, self.maxLen)

0 commit comments

Comments
 (0)