opensafely-core / opensafely-core/opencodelists
`UnicodeDecodeError` when reading csv file
Open
Nobody has claimed this yet.
bug
csv
deck-scrubbing
- Dominant language
- Python
- Stars
- 60
- Forks
- 16
- Avg merge
- 4d 12h
- Merged PRs (30d)
- 17
Description
Sentry Issue: OPENCODELISTS-TF
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x83 in position 11: invalid start byte
decoding with 'utf-8-sig' codec failed
(8 additional frame(s) were not displayed)
...
File "codelists/views/decorators.py", line 40, in wrapped_view
return view_fn(request, codelist)
File "codelists/views/decorators.py", line 139, in wrapped_view
return view_fn(request, obj, *args, **kwargs)
File "codelists/views/version_upload.py", line 19, in version_upload
return handle_post(request, codelist)
File "codelists/views/version_upload.py", line 30, in handle_post
if form.is_valid():
File "codelists/forms.py", line 95, in clean_csv_data
data = self.cleaned_data["csv_data"].read().decode("utf-8-sig")
Seems this could be caused by non-decodable data in the file. Ideally we would handle this case and provide a sensible message to user.
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 in codelists/forms.py at clean_csv_data, line 95, where uploaded CSV data is decoded as utf-8-sig. Reproduce the upload with a file containing non-decodable data and inspect the surrounding form validation; done means the user receives a sensible validation message instead of an unhandled UnicodeDecodeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100