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

Make AttributeErrors on erhQL objects as helpful as possible #2137

Open
evansd opened this issue Oct 3, 2024 · 0 comments
Open

Make AttributeErrors on erhQL objects as helpful as possible #2137

evansd opened this issue Oct 3, 2024 · 0 comments

Comments

@evansd
Copy link
Contributor

evansd commented Oct 3, 2024

When a user tries to access an non-existent attribute on an ehrQL object, we should try to make the error as helpful as possible.

There are (at least) two distinct cases here:

1. Typoing the name of an attribute which does exist on the object

Fortunately Python now handles this pretty nicely out-of-the-box and offers suggestions e.g.

$ python -c 'from ehrql.tables.core import patients; patients.date_of_brith'

Traceback (most recent call last):
  File "<string>", line 1, in <module>
AttributeError: 'patients' object has no attribute 'date_of_brith'. Did you mean: 'date_of_birth'?

2. Using an attribute which doesn't exist on this object but does on others

Examples might be calling first_for_patient() on a un-sorted frame, or calling sum_for_patient() on a non-numeric series.

We ought to be able to spot such errors and generate a more helpful error message.


Extracted from #505

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant