Skip to content

fix: validate invalid dicom uploads before processing#56

Open
AlwinXue wants to merge 1 commit intoOSIPI:mainfrom
AlwinXue:alwin/fix-issue-31
Open

fix: validate invalid dicom uploads before processing#56
AlwinXue wants to merge 1 commit intoOSIPI:mainfrom
AlwinXue:alwin/fix-issue-31

Conversation

@AlwinXue
Copy link
Copy Markdown

@AlwinXue AlwinXue commented Mar 31, 2026

Hi mentors! 👋

This PR addresses the missing DICOM pre-flight validation reported in Issue #31.

The Problem:
The /api/report/process/dicom endpoint returned a 500 Server Error when users uploaded files that were not valid DICOMs. The route saved the uploads and immediately called get_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 Request with No valid DICOM files provided.
Test Alignment: Updated the invalid-file backend test to hit the correct /api/report/process/dicom route 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" (with DYLD_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

@AlwinXue AlwinXue force-pushed the alwin/fix-issue-31 branch from 3e83aa4 to c931b91 Compare March 31, 2026 01:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Missing pre-flight validation on empty/invalid DICOM directory uploads causes 500 Server Error

1 participant