FastAPI CSV Upload Service Had Four Bugs Its Tests Missed
The author found that a CSV upload endpoint returned a plain 500 error instead of the intended 413 response when a file exceeded the size limit. The root cause was a nonexistent status constant name in the Starlette version used, which raised an AttributeError that the service's error handling did not catch. The service also lacked an encoding policy, so Latin-1 files and binary files renamed as CSVs were handled without validation. A size check that ran only after the entire file was read, along with a more permissive-than-expected CORS configuration, were also identified as problems. The author fixed each issue and added targeted tests, including one that checks rejection of oversized files by temporarily lowering the limit.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in