@@ -480,18 +480,17 @@ def validate_metadata(json_record):
480480 errors .append ("Each 'subject' must have a 'subject' key." )
481481
482482 # Check for 'dates'
483- if "dates" not in json_record :
484- errors .append ("'dates' field is missing." )
485- elif not isinstance (json_record ["dates" ], list ) or len (json_record ["dates" ]) == 0 :
486- errors .append ("'dates' should be a non-empty list." )
487- else :
488- for date in json_record ["dates" ]:
489- if (
490- not isinstance (date , dict )
491- or "date" not in date
492- or "dateType" not in date
493- ):
494- errors .append ("Each 'date' must have 'date' and 'dateType'." )
483+ if "dates" in json_record :
484+ if not isinstance (json_record ["dates" ], list ) or len (json_record ["dates" ]) == 0 :
485+ errors .append ("'dates' should be a non-empty list." )
486+ else :
487+ for date in json_record ["dates" ]:
488+ if (
489+ not isinstance (date , dict )
490+ or "date" not in date
491+ or "dateType" not in date
492+ ):
493+ errors .append ("Each 'date' must have 'date' and 'dateType'." )
495494
496495 # Check for 'creators'
497496 if "creators" not in json_record :
@@ -601,10 +600,9 @@ def validate_metadata(json_record):
601600 errors .append ("'publisher' should be a string." )
602601
603602 # Check for 'publicationYear'
604- if "publicationYear" not in json_record :
605- errors .append ("'publicationYear' field is missing." )
606- elif not isinstance (json_record ["publicationYear" ], str ):
607- errors .append ("'publicationYear' should be a string." )
603+ if "publicationYear" in json_record :
604+ if not isinstance (json_record ["publicationYear" ], str ):
605+ errors .append ("'publicationYear' should be a string." )
608606
609607 # Check for 'types'
610608 if "types" not in json_record :
0 commit comments