Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error message when using batch inventory but missing container #2056

Merged
merged 2 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions server/api/ballot_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,7 @@ def process() -> None:
)

columns = [
CSVColumnType(
CONTAINER,
CSVValueType.TEXT,
required_column=is_counting_group_required,
),
CSVColumnType(CONTAINER, CSVValueType.TEXT, required_column=False),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be slightly confusing to readers that we indicate the column isn't required, but later on enforce it in L158. Thoughts on allowing an error message override to be specified in the CSVColumnType? I could see it being overkill, so if you agree, maybe just add a comment here on why we mark required_column=False and enforce with special logic later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I'll add a comment!

CSVColumnType(
TABULATOR,
CSVValueType.TEXT,
Expand Down Expand Up @@ -158,14 +154,16 @@ def process() -> None:
num_ballots = 0

for row_index, row in enumerate(manifest_csv):
counting_group = row.get(CONTAINER, None)
if (
is_counting_group_required
and not counting_group in counting_group_allowset
):
raise CSVParseError(
f"Invalid value for column \"Container\", row {row_index+2}: \"{counting_group}\". Use the Batch Audit File Preparation Tool to create your ballot manifest, or correct this value to one of the following: {', '.join(counting_group_allowlist)}."
)
if is_counting_group_required:
if not CONTAINER in row:
raise CSVParseError(
'Missing required column "Container". Use the Batch Audit File Preparation Tool to create your ballot manifest.'
)
counting_group = row.get(CONTAINER)
if counting_group not in counting_group_allowset:
raise CSVParseError(
f"Invalid value for column \"Container\", row {row_index+2}: \"{counting_group}\". Use the Batch Audit File Preparation Tool to create your ballot manifest, or correct this value to one of the following: {', '.join(counting_group_allowlist)}."
)

batch = Batch(
id=str(uuid.uuid4()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -567,3 +567,34 @@ def test_sample_extra_batches_with_invalid_counting_group(
},
},
)

# Missing the "Container" column
set_logged_in_user(
client, UserType.JURISDICTION_ADMIN, default_ja_email(election_id)
)
rv = upload_ballot_manifest(
client,
io.BytesIO(b"Batch Name,Number of Ballots\n" b"Batch 1,500\n"),
election_id,
jurisdiction_ids[0],
)
assert_ok(rv)

rv = client.get(
f"/api/election/{election_id}/jurisdiction/{jurisdiction_ids[0]}/ballot-manifest"
)
compare_json(
json.loads(rv.data),
{
"file": {
"name": asserts_startswith("manifest"),
"uploadedAt": assert_is_date,
},
"processing": {
"status": ProcessingStatus.ERRORED,
"startedAt": assert_is_date,
"completedAt": assert_is_date,
"error": 'Missing required column "Container". Use the Batch Audit File Preparation Tool to create your ballot manifest.',
},
},
)