Do better checking for fields that may be empty or unset

This commit is contained in:
John Donaldson 2019-08-15 00:07:22 +01:00
parent 470e01b437
commit 51124ec80b
1 changed files with 3 additions and 1 deletions

View File

@ -71,7 +71,9 @@ class MothValidator:
def check_fields(self, puzzle):
"""Check if the puzzle has the requested fields"""
for field in self.required_fields:
if not hasattr(puzzle, field):
if not hasattr(puzzle, field) or \
getattr(puzzle,field) is None or \
getattr(puzzle,field) == "":
raise MothValidationError("Missing field %s" % (field,))
@staticmethod