This repository was archived by the owner on Aug 27, 2023. It is now read-only.

Description
When a field is set to None due to an explicit None value, there could be the option to set it to its default value before validation/
I've written a field validator loop (#29) and I've just recently added this check to it. Ideally you would want to check if nullable is false first but it looks like nullable isn't an attribute (it's just part of the init to append the not null check.)
It might be possible to do what I propose in a check method, but python isn't my strongest language.
def validate(self):
self._fields_with_errors = []
for field in self.meta_.fields.values():
try:
#check if the field's value is None and if it has a default, if it's none, set it to it's default.
if field.resolve(self) is None and field.default is not None:
setattr(self, field.name, field.default)
field.validate(self)
except ValueError as e:
res = re.search('Validation check on field (.*) failed for value (.*)', str(e))
self._fields_with_errors.append(res.group(1))
return len(self._fields_with_errors) == 0
My other suggestion is to treat "" as None for the nullable check for str field types. Or to at least have that option. This one's not a big deal and can easily be overcome with a check.