opensafely-core / opensafely-core/opencodelists
AssertionError on accessing invalid codelist
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 60
- Forks
- 16
- Avg merge
- 4d 12h
- Merged PRs (30d)
- 17
Description
Why are we doing this?
When codelists with invalid codelists are accessed, we get an assertion error, at a surprising location. The site 500s and the user goes to the 500 page then is redirected to the home page with the confusing message: "This codelist has not been published".
Sentry Issue: OPENCODELISTS-TD
One of [the] old codelists is borked. ICD-10 coding system (presumably uploaded in old school yolomode) but is full of SNOMED CT codes. Someone or something tried to download it.
Offending URL: http://www.opencodelists.org/codelist/user/rriefu/icd/327e171a/ (best to access in a development environment with the production backup loaded).
Bots fairly regularly hit this page. We should avoid 500 errors which spam our Sentry issue list and lead to noisy alerts.
Stack trace
AssertionError:
(2 additional frame(s) were not displayed)
...
File "codelists/views/decorators.py", line 74, in wrapped_view
rsp = view_fn(request, version, **view_kwargs)
File "codelists/views/version.py", line 26, in version
hierarchy = clv.codeset.hierarchy
File "codelists/models.py", line 512, in codeset
return self._old_style_codeset()
File "codelists/models.py", line 522, in _old_style_codeset
return Codeset.from_codes(set(self.codes), self.hierarchy)
File "codelists/codeset.py", line 83, in from_codes
assert sorted(codeset.codes()) == sorted(codes)
How will we know when it's done?
Accessing the page leads to a helpful error message and redirect and no unhandled error.
What are we doing?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at codelists/views/version.py and follow the failing access through codelists/models.py and codelists/codeset.py, using the provided offending URL in a development environment with the production backup. Trace how invalid codelists reach the assertion and identify the existing error-handling path. Done means the page shows a helpful error, redirects appropriately, and produces no unhandled 500 error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100