Project-MONAI / MONAILabel

MONAI Label is an intelligent open source image labeling and learning tool.
https://docs.monai.io/projects/label
Apache License 2.0
567 stars 185 forks source link

Wrong string formatting causing image upload to crash in 3D Slicer #1601

Closed che85 closed 7 months ago

che85 commented 7 months ago

commit https://github.com/Project-MONAI/MONAILabel/commit/055fdc2427d6313e4b1c11cff067a6f9e4d97fa2 introduces a bug

When using 3D Slicer and trying to upload an image to the server

Traceback (most recent call last):
  File "/Users/herzc/sources/py/MONAILabel/plugins/slicer/MONAILabel/MONAILabel.py", line 1376, in onUploadImage
    if not self.getPermissionForImageDataUpload():
  File "/Users/herzc/sources/py/MONAILabel/plugins/slicer/MONAILabel/MONAILabel.py", line 1363, in getPermissionForImageDataUpload
    _(
KeyError: 'server_url'

https://github.com/Project-MONAI/MONAILabel/blob/ac0af6d4886bcd10f4a7f09419446ba0ba20eca0/plugins/slicer/MONAILabel/MONAILabel.py#L1363-L1368

if using string formatting, it should be

            _(
                "Source volume - without any additional patient information -"
                " will be sent to remote data processing server: {}.\n\n"
                "Click 'OK' to proceed with the segmentation.\n"
                "Click 'Cancel' to not upload any data and cancel segmentation.\n"
            ).format(self.serverUrl()),

I don't know if any other functionality is affected by that commit.

lassoan commented 7 months ago

It should be

_( 
     "Source volume - without any additional patient information -" 
     " will be sent to remote data processing server: {server_url}.\n\n" 
     "Click 'OK' to proceed with the segmentation.\n" 
     "Click 'Cancel' to not upload any data and cancel segmentation.\n" 
 ).format(server_url=self.serverUrl()), 

_() is for internationalization (to be able to translate the message to different languages). The named placeholder is not strictly needed if there is only a single placeholder, but useful for translators.

Could you test if the fix above works and maybe submit a pull request to MONAILabel?

wien2020 commented 7 months ago

I had the same problem “Failed to run inference in MONAl Label Server.”

Traceback (most recent call last): File "/Applications/Slicer.app/Contents/Extensions-32390/MONAILabel/lib/Slicer-5.6/qt-scripted-modules/MONAILabel.py", line 1545, in onClickSegmentation result_file, params = self.logic.infer(model, image_file, params, session_id=self.getSessionId()) File "/Applications/Slicer.app/Contents/Extensions-32390/MONAILabel/lib/Slicer-5.6/qt-scripted-modules/MONAILabel.py", line 1526, in getSessionId self.onUploadImage(initsample=False, session=True) File "/Applications/Slicer.app/Contents/Extensions-32390/MONAILabel/lib/Slicer-5.6/qt-scripted-modules/MONAILabel.py", line 1376, in onUploadImage if not self.getPermissionForImageDataUpload(): File "/Applications/Slicer.app/Contents/Extensions-32390/MONAILabel/lib/Slicer-5.6/qt-scripted-modules/MONAILabel.py", line 1363, in getPermissionForImageDataUpload ( IndexError: Replacement index 0 out of range for positional args tuple