fix: clean up temporary pdf files after response#57
Open
AlwinXue wants to merge 1 commit intoOSIPI:mainfrom
Open
fix: clean up temporary pdf files after response#57AlwinXue wants to merge 1 commit intoOSIPI:mainfrom
AlwinXue wants to merge 1 commit intoOSIPI:mainfrom
Conversation
Made-with: Cursor
76634ca to
8d4ad3a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi mentors! 👋
This PR addresses the temporary PDF file leak reported in Issue #17.
The Problem:
The
/api/report/report-pdfendpoint creates a temporary PDF usingNamedTemporaryFile(delete=False)and returns it throughFileResponse, but nothing cleans that file up afterward. Over time, repeated PDF downloads can leave orphaned files on disk.The Solution:
Response Cleanup: Added a
BackgroundTaskto theFileResponseso the generated PDF is deleted after the response is sent.Regression Test: Added a targeted backend test that patches the temporary file and PDF writer, then verifies the response succeeds and the temporary file is removed afterward.
Validation:
Ran
python -m pytest tests/test_report.py -q -k "test_report_pdf_endpoint_removes_temp_file"(withDYLD_FALLBACK_LIBRARY_PATH=/opt/homebrew/lib) and the new cleanup test passed.Note: the broader backend test file still contains unrelated failures from other open issues, so validation here is intentionally scoped to Issue #17.
Fixes #17