Skip to content
This repository was archived by the owner on Oct 2, 2025. It is now read-only.

Commit cfc9e86

Browse files
committed
Updated validation of model
1 parent 1270f27 commit cfc9e86

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

rebase/core/model.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,24 @@ def rules(self) -> Dict[str, List[Validator]]:
4545
def scenarios(self) -> Dict[str, List[str]]:
4646
return {}
4747

48-
def validate(self) -> bool:
48+
def validate(self, attribute = None) -> bool:
4949
is_valid = True
50-
self._errors.clear()
50+
if not attribute:
51+
self._errors.clear()
52+
else:
53+
self._errors.update({attribute: []})
5154

5255
for attr, ruleset in self.rules().items():
53-
if attr not in self.attributes:
56+
if attribute and attr != attribute:
5457
continue
5558
for rule in ruleset:
5659
value = getattr(self, attr, None)
57-
if rule.required or value is not None:
58-
is_valid &= rule.validate(value)
59-
self.add_errors(attr, rule.errors)
60+
if rule.required and value is None:
61+
self.add_errors(attr, [f'`{attr}` is a required field.'])
62+
is_valid = False
63+
continue
64+
is_valid &= rule.validate(value)
65+
self.add_errors(attr, rule.errors)
6066

6167
return is_valid
6268

0 commit comments

Comments
 (0)