Skip to content

DICOM converter never copies files to temp_dir — dcm2niix subprocess is never called #40

@Devguru-codes

Description

@Devguru-codes

Location

package/src/pyaslreport/converters/dicom_to_nifti_converter.py:26-51

Description

The convert() method creates a temp_dir and iterates over DICOM files to read headers, but never actually copies the DICOM files into temp_dir. The os.listdir(temp_dir) check on line 50 always finds an empty directory and returns early. The dcm2niix subprocess is never called.

Reproduction (on main branch)

Reproducible Code (Python)

# reproduce_bug7.py — Run: .venv\Scripts\python.exe bug_7\reproduce_bug7.py
import inspect
from pyaslreport.converters.dicom_to_nifti_converter import DICOM2NiFTIConverter

# Inspect the convert() source — no shutil.copy anywhere
src = inspect.getsource(DICOM2NiFTIConverter.convert)
print("shutil.copy in source:", "shutil.copy" in src)  # False on main (bug)

# The module doesn't even import shutil
module_file = inspect.getfile(DICOM2NiFTIConverter)
with open(module_file, 'r') as f:
    print("import shutil:", "import shutil" in f.read())  # False on main (bug)

API Endpoint Reproduction

# api_reproduce_bug7.py — Shows converter returns early with "No DICOM files found"
import tempfile, pydicom
from pyaslreport.converters.dicom_to_nifti_converter import DICOM2NiFTIConverter

# Create 2 valid DICOM files and call converter
with tempfile.TemporaryDirectory() as test_dir:
    # ... (create minimal DICOM files with pydicom)
    result = DICOM2NiFTIConverter.convert(
        dcm_files=[dcm_path1, dcm_path2], nifti_file=None
    )
    _, _, _, _, error_msg = result
    print(f"error_msg: {error_msg}")
    # On main:  "No DICOM files found." — despite valid input!
    # After fix: (attempts dcm2niix — files were copied to temp_dir)

Automated Results on main branch

# Test Status Detail
T1 convert() copies DICOM files into temp_dir FAIL No file copy operation found
T2 temp_dir receives files before dcm2niix FAIL Loop reads headers but writes nothing
T3 os.listdir check doesn't cause false early return FAIL Always returns early — temp_dir empty
T4 Module imports shutil FAIL shutil not imported

Summary: PASSED=0 FAILED=4

API/Converter Output on main

Input: 2 valid DICOM files
Converter Output:
  converted_files:     None
  converted_filenames: None
  nifti_file:          None
  file_type:           nifti
  error_msg:           No DICOM files found.

>> BUG PRESENT: Converter returned 'No DICOM files found.' despite valid DICOM input.
   Root cause: Files were never copied to temp_dir.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions