feat: useful error when submission has inconsistent date (#8576)

* chore: handle errors in app-configure-blobstore.py

* feat: sensible error for inconsistent <date>
This commit is contained in:
Jennifer Richards 2025-02-21 11:49:16 -04:00 committed by GitHub
parent 7f3488c5c2
commit fb310e5ce2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 3 deletions

View file

@ -58,7 +58,7 @@ from ietf.utils.draft import PlaintextDraft
from ietf.utils.mail import is_valid_email
from ietf.utils.text import parse_unicode, normalize_text
from ietf.utils.timezone import date_today
from ietf.utils.xmldraft import XMLDraft
from ietf.utils.xmldraft import InvalidMetadataError, XMLDraft
from ietf.person.name import unidecode_name
@ -1201,6 +1201,11 @@ def process_submission_xml(filename, revision):
if not title:
raise SubmissionError("Could not extract a valid title from the XML")
try:
document_date = xml_draft.get_creation_date()
except InvalidMetadataError as err:
raise SubmissionError(str(err)) from err
return {
"filename": xml_draft.filename,
"rev": xml_draft.revision,
@ -1210,7 +1215,7 @@ def process_submission_xml(filename, revision):
for auth in xml_draft.get_author_list()
],
"abstract": None, # not supported from XML
"document_date": xml_draft.get_creation_date(),
"document_date": document_date,
"pages": None, # not supported from XML
"words": None, # not supported from XML
"first_two_pages": None, # not supported from XML

View file

@ -159,7 +159,16 @@ class XMLDraft(Draft):
day = today.day
else:
day = 15
return datetime.date(year, month, day)
try:
creation_date = datetime.date(year, month, day)
except Exception:
raise InvalidMetadataError(
"The <date> element in the <front> section specified an incomplete date "
"that was not consistent with today's date. If you specify only a year, "
"it must be the four-digit current year. To use today's date, omit the "
"date tag or use <date/>."
)
return creation_date
def get_creation_date(self):
return self.parse_creation_date(self.xmlroot.find("front/date"))
@ -269,3 +278,7 @@ class XMLParseError(Exception):
class InvalidXMLError(Exception):
"""File is not valid XML"""
pass
class InvalidMetadataError(Exception):
"""XML is well-formed but has invalid metadata"""