Skip to content

Provide better error message for expected column key error in assurance testing #2681

@alarthast

Description

@alarthast

Reported on Slack by a user in this thread.

If a key in the user's provided expected_columns does not appear in the actual dataset, Python raises a KeyError with an error message that might not be immediately helpful to the user:

File "/app/ehrql/assurance.py", line 71, in validate
         if (validation_result := validate_patient(patient_id, patient, query_results))
                                  ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       File "/app/ehrql/assurance.py", line 139, in validate_patient
         if expected[k] != actual[k]
                           ~~~~~~^^^
     KeyError: 'reps_ids_differ'

We might want to catch the mismatch earlier and return a custom error message.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions