Skip to content

"Remove all results" fails with AttributeError when ROI was removed #286

@PierreRaybaut

Description

@PierreRaybaut

"Remove all results" fails with AttributeError when ROI was removed

Description

When trying to remove all analysis results via Analysis > Remove results > Remove all results, the operation fails with an AttributeError if the results contain ROI information but the ROI was subsequently removed from the object.

Steps to Reproduce

  1. Create or open an image/signal in DataLab
  2. Add a Region of Interest (ROI) to the object
  3. Run an analysis that uses the ROI (e.g., Centroid for images)
  4. Remove the ROI from the object
  5. Select the object and try to delete all results via Analysis > Remove results > Remove all results

Expected Behavior

The results should be deleted successfully, regardless of whether the ROI still exists on the object.

Actual Behavior

An AttributeError is raised because the code attempts to access obj.roi.get_single_roi_title() when obj.roi is None.

Error Traceback

Traceback (most recent call last):
  File "C:\Dev\Projets\DataLab\datalab\gui\panel\base.py", line 3258, in delete_results
    rdatadict = create_resultdata_dict(objs)
  File "C:\Dev\Projets\DataLab\datalab\adapters_metadata\common.py", line 141, in create_resultdata_dict
    rdata.append(adapter, obj)
  File "C:\Dev\Projets\DataLab\datalab\adapters_metadata\common.py", line 92, in append
    roititle = obj.roi.get_single_roi_title(i_roi)
AttributeError: 'NoneType' object has no attribute 'get_single_roi_title'

Root Cause

In datalab/adapters_metadata/common.py, the ResultData.append() method checks if i_roi >= 0 before accessing obj.roi.get_single_roi_title(i_roi), but it doesn't check if obj.roi is None. This can happen when:

  1. Results were computed with a ROI
  2. The ROI was later removed from the object
  3. The user attempts to delete all results

Fix

Add a None check for obj.roi before attempting to call get_single_roi_title():

if i_roi >= 0 and obj.roi is not None:
    roititle = obj.roi.get_single_roi_title(i_roi)
    ylabel += f"|{roititle}"

Affected Versions

  • DataLab 1.0.x (and earlier versions)

Labels

  • bug
  • results
  • ROI

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions