Closed partyzan closed 10 years ago
Looking at the Document.validate_fields
makes me think this is a bug and the validate methods in the fields should be changed to support None.
def validate_fields(self):
for name, field in list(self._fields.items()):
value = self.get_field_value(name)
if field.required and field.is_empty(value):
raise InvalidDocumentError("Field '%s' is required." % name)
if not field.validate(value):
raise InvalidDocumentError("Field '%s' must be valid." % name)
return True
If this is indeed a bug, I created a pull request with a simple fix - #76
Hey, I see the change was merged. Any estimate on when it will be released ?
Thanks
Released under 0.8.10. thanks a lot for your contribution @partyzan.
Unfortunately my previous fix was not complete, it failed to serialize and deserialize empty values. I have fixed that and added unit tests that test empty fields. See pull request #77.
Thanks.
Currently validation of the document fails if one of these fields is not present even if it is marked as optional. Is that a design decision or a bug ?
The test fails on the first with the following:
According to what I see in the code, for StringField validate checks if it is None and returns true, while for int for example it just tries to do
int(value)
which obviously fails.Thanks for the help :)