fix: validate invalid dicom uploads before processing#56
Open
AlwinXue wants to merge 1 commit intoOSIPI:mainfrom
Open
fix: validate invalid dicom uploads before processing#56AlwinXue wants to merge 1 commit intoOSIPI:mainfrom
AlwinXue wants to merge 1 commit intoOSIPI:mainfrom
Conversation
Made-with: Cursor
3e83aa4 to
c931b91
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 missing DICOM pre-flight validation reported in Issue #31.
The Problem:
The
/api/report/process/dicomendpoint returned a 500 Server Error when users uploaded files that were not valid DICOMs. The route saved the uploads and immediately calledget_bids_metadata(), which eventually failed because the upload directory contained no readable DICOM headers. That failure was then surfaced as a generic 500 instead of a clear client error.The Solution:
Pre-flight Validation: Added a validation step after saving uploads that calls
get_dicom_header()on the uploaded directory before report generation starts.Clear Client Error: If no valid DICOM files are found, the route now cleans up the temporary upload directory and returns
400 Bad RequestwithNo valid DICOM files provided.Test Alignment: Updated the invalid-file backend test to hit the correct
/api/report/process/dicomroute and assert the deterministic 400 response.Validation:
Ran
python -m pytest tests/test_report.py -q -k "test_get_report_dicom_no_files or test_get_report_dicom_with_invalid_file"(withDYLD_FALLBACK_LIBRARY_PATH=/opt/homebrew/lib) and both DICOM endpoint tests passed.Note: the full backend test file still contains unrelated failures tied to other open issues, so validation here is scoped to Issue #31.
Fixes #31