opensafely-core / ehrql

ehrQL: the electronic health record query language for OpenSAFELY
https://docs.opensafely.org/ehrql/
Other
7 stars 3 forks source link

Give context-appropriate hint for domain mismatch errors #2216

Closed evansd closed 1 week ago

evansd commented 1 week ago

Since #1873 we attempt to give a helpful error message for "domian mismatch" errors with some hints as to how to go about fixing it. However we fail to mention the possible solution of using is_in() which we've supported since #1795.

This is actively unhelpful for users who might reasonably assume that the options suggested are the only ones available. For example, see: https://bennettoxford.slack.com/archives/C33TWNQ1J/p1731320032663639

This is only relevant where the problematic operation is an equality comparison, so we only add the hint in that context.

The error now looks like this:

Cannot combine series which are drawn from different tables and both
have more than one value per patient.

To address this, try one of the following:

 * Use `x.is_in(y)` instead of `x == y` to check if values from
   one series match any of the patient's values in the other.

 * Reduce one series to have only one value per patient by using
   an aggregation like `maximum_for_patient()`.

 * Pick a single row for each patient from the table using
   `first_for_patient()`.
cloudflare-workers-and-pages[bot] commented 1 week ago

Deploying databuilder-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 6e7cf23
Status: ✅  Deploy successful!
Preview URL: https://c6603691.databuilder.pages.dev
Branch Preview URL: https://evansd-domain-mismatch-hint.databuilder.pages.dev

View logs