Skip to content

Commit

Permalink
format-dates: Error on date fields that do not exist
Browse files Browse the repository at this point in the history
The user should be providing date fields that exist in the record.
Raise a loud error if a field does not exist!
  • Loading branch information
joverlee521 committed Jul 1, 2024
1 parent 12b3522 commit d55130f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 1 addition & 3 deletions augur/curate/format_dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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]

0 comments on commit d55130f

Please sign in to comment.