Skip to content

Commit fb310e5

Browse files
feat: useful error when submission has inconsistent date (#8576)
* chore: handle errors in app-configure-blobstore.py * feat: sensible error for inconsistent <date>
1 parent 7f3488c commit fb310e5

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

ietf/submit/utils.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
from ietf.utils.mail import is_valid_email
5959
from ietf.utils.text import parse_unicode, normalize_text
6060
from ietf.utils.timezone import date_today
61-
from ietf.utils.xmldraft import XMLDraft
61+
from ietf.utils.xmldraft import InvalidMetadataError, XMLDraft
6262
from ietf.person.name import unidecode_name
6363

6464

@@ -1201,6 +1201,11 @@ def process_submission_xml(filename, revision):
12011201
if not title:
12021202
raise SubmissionError("Could not extract a valid title from the XML")
12031203

1204+
try:
1205+
document_date = xml_draft.get_creation_date()
1206+
except InvalidMetadataError as err:
1207+
raise SubmissionError(str(err)) from err
1208+
12041209
return {
12051210
"filename": xml_draft.filename,
12061211
"rev": xml_draft.revision,
@@ -1210,7 +1215,7 @@ def process_submission_xml(filename, revision):
12101215
for auth in xml_draft.get_author_list()
12111216
],
12121217
"abstract": None, # not supported from XML
1213-
"document_date": xml_draft.get_creation_date(),
1218+
"document_date": document_date,
12141219
"pages": None, # not supported from XML
12151220
"words": None, # not supported from XML
12161221
"first_two_pages": None, # not supported from XML

ietf/utils/xmldraft.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,16 @@ def parse_creation_date(date_elt):
159159
day = today.day
160160
else:
161161
day = 15
162-
return datetime.date(year, month, day)
162+
try:
163+
creation_date = datetime.date(year, month, day)
164+
except Exception:
165+
raise InvalidMetadataError(
166+
"The <date> element in the <front> section specified an incomplete date "
167+
"that was not consistent with today's date. If you specify only a year, "
168+
"it must be the four-digit current year. To use today's date, omit the "
169+
"date tag or use <date/>."
170+
)
171+
return creation_date
163172

164173
def get_creation_date(self):
165174
return self.parse_creation_date(self.xmlroot.find("front/date"))
@@ -269,3 +278,7 @@ def parser_msgs(self):
269278
class InvalidXMLError(Exception):
270279
"""File is not valid XML"""
271280
pass
281+
282+
283+
class InvalidMetadataError(Exception):
284+
"""XML is well-formed but has invalid metadata"""

0 commit comments

Comments
 (0)