Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Codelist create form: Check for
UnicodeDecodeError
.
Otherwise there can be an unhandled exception and 500 error if trying to upload a file encoded dfferently, with bad content, or if an XLSX is accidentally uploaded in place of CSV text. From Sentry reports, both cases seem fairly common. The text should be clear and actionable for all users, including those who might mistakenly upload an XLSX file. It should also provide enough detail to help more experienced users resolve issues with text encoding or file content. We shouldn't enforce file extension validation here. The problem isn't the filename; it's the file's encoding. We can process valid CSV data regardless of the .csv extension, which is just a convention. Adding this requirement could complicate matters unnecessarily, confuse users, or frustrate those who don’t follow the .csv naming convention. I considered checking the file extension to mention if it wasn't .csv, but it didn’t seem necessary. The error message should explain clearly what the user needs to do in either case. There were no tests of this form specifically so I added a basic valid form test as well as the test of the error case. codelists/tests/views/test_codelist_create.py has tests of the view as a whole but they seemed to relate to behaviour before or after the form is processed.
- Loading branch information