From d55130f77287917a9d90e023c6d246512082f12e Mon Sep 17 00:00:00 2001 From: Jover Lee Date: Mon, 1 Jul 2024 13:29:11 -0700 Subject: [PATCH] format-dates: Error on date fields that do not exist The user should be providing date fields that exist in the record. Raise a loud error if a field does not exist! --- augur/curate/format_dates.py | 4 +--- .../cram/format-dates/date-field-not-found-error.t | 11 +++++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 tests/functional/curate/cram/format-dates/date-field-not-found-error.t diff --git a/augur/curate/format_dates.py b/augur/curate/format_dates.py index 7e39830cd..063096de4 100644 --- a/augur/curate/format_dates.py +++ b/augur/curate/format_dates.py @@ -188,10 +188,8 @@ def run(args, records): for field in args.date_fields: date_string = record.get(field) - # TODO: This should raise an error if the expected date field does - # not exist in the the record if date_string is None: - continue + raise AugurError(f"Expected date field {field!r} not found in record {record_id!r}.") formatted_date_string = format_date(date_string, args.expected_date_formats) if formatted_date_string is None: diff --git a/tests/functional/curate/cram/format-dates/date-field-not-found-error.t b/tests/functional/curate/cram/format-dates/date-field-not-found-error.t new file mode 100644 index 000000000..6d5162e13 --- /dev/null +++ b/tests/functional/curate/cram/format-dates/date-field-not-found-error.t @@ -0,0 +1,11 @@ +Setup + + $ export AUGUR="${AUGUR:-$TESTDIR/../../../../../bin/augur}" + +Providing a date field that does not exist in the record should result in an error. + + $ echo '{"record": 1, "date": "2024-01-01"}' \ + > | ${AUGUR} curate format-dates \ + > --date-fields "bad-date-field" + ERROR: Expected date field 'bad-date-field' not found in record 0. + [2]