Skip to content

Commit 1645046

Browse files
committed
Fix analysis params not cleared after deleting results
Closes #285
1 parent 30be9ae commit 1645046

File tree

6 files changed

+120
-2
lines changed

6 files changed

+120
-2
lines changed

datalab/gui/actionhandler.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@
5050
from datalab.adapters_metadata import GeometryAdapter, TableAdapter, have_results
5151
from datalab.config import Conf, _
5252
from datalab.gui import newobject
53+
from datalab.gui.processor.base import (
54+
clear_analysis_parameters,
55+
extract_analysis_parameters,
56+
)
5357
from datalab.widgets import fitdialog
5458

5559
if TYPE_CHECKING:
@@ -361,6 +365,15 @@ def _delete_single_result(
361365
obj: Object containing the result
362366
adapter: Adapter for the result to delete
363367
"""
368+
# Check if this result matches the stored analysis parameters
369+
# If so, clear them to prevent auto-recompute from attempting to
370+
# recompute the deleted analysis when ROI changes
371+
analysis_params = extract_analysis_parameters(obj)
372+
if (
373+
analysis_params is not None
374+
and analysis_params.func_name == adapter.func_name
375+
):
376+
clear_analysis_parameters(obj)
364377
adapter.remove_from(obj)
365378
# Update properties panel to reflect the removal
366379
if obj is self.panel.objview.get_current_object():

datalab/gui/panel/base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
from datalab.gui.processor.base import (
8080
PROCESSING_PARAMETERS_OPTION,
8181
ProcessingParameters,
82+
clear_analysis_parameters,
8283
extract_processing_parameters,
8384
insert_processing_parameters,
8485
)
@@ -3276,6 +3277,9 @@ def delete_results(self) -> None:
32763277
# Remove all table and geometry results using adapter methods
32773278
TableAdapter.remove_all_from(obj)
32783279
GeometryAdapter.remove_all_from(obj)
3280+
# Clear analysis parameters to prevent auto-recompute from
3281+
# attempting to recompute deleted analyses when ROI changes
3282+
clear_analysis_parameters(obj)
32793283
if obj is self.objview.get_current_object():
32803284
self.objprop.update_properties_from(obj)
32813285
# Update action states to reflect the removal

datalab/gui/processor/base.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,21 @@ def insert_processing_parameters(
195195
obj.set_metadata_option(PROCESSING_PARAMETERS_OPTION, pp.to_dict())
196196

197197

198+
def clear_analysis_parameters(obj: SignalObj | ImageObj) -> None:
199+
"""Clear analysis parameters from object metadata.
200+
201+
This removes the stored analysis parameters (1-to-0 operations) from the object.
202+
Should be called when all analysis results are deleted to prevent the
203+
auto_recompute_analysis function from attempting to recompute deleted analyses.
204+
205+
Args:
206+
obj: Signal or Image object
207+
"""
208+
key = f"__{ANALYSIS_PARAMETERS_OPTION}"
209+
if key in obj.metadata:
210+
del obj.metadata[key]
211+
212+
198213
def run_with_env(func: Callable, args: tuple, env_json: str) -> CompOut:
199214
"""Wrapper to apply environment config before calling func
200215

datalab/tests/features/common/result_deletion_unit_test.py

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212

1313
from __future__ import annotations
1414

15-
from sigima.objects import Gauss2DParam, create_image_from_param
15+
from sigima.objects import Gauss2DParam, create_image_from_param, create_image_roi
1616
from sigima.tests.data import create_paracetamol_signal
1717

1818
from datalab.adapters_metadata import GeometryAdapter, TableAdapter
1919
from datalab.config import Conf
2020
from datalab.env import execenv
21+
from datalab.gui.processor.base import extract_analysis_parameters
2122
from datalab.objectmodel import get_uuid
2223
from datalab.tests import datalab_test_app_context
2324

@@ -91,6 +92,69 @@ def test_delete_results_signal():
9192
execenv.print(" ✓ Stats result deleted")
9293

9394

95+
def test_delete_results_clears_analysis_parameters():
96+
"""Test that deleting results also clears analysis parameters.
97+
98+
This prevents auto_recompute_analysis from attempting to recompute
99+
deleted analyses when ROI changes.
100+
"""
101+
with datalab_test_app_context(console=False) as win:
102+
execenv.print("Test delete_results clears analysis parameters:")
103+
panel = win.imagepanel
104+
105+
# Create a test image
106+
param = Gauss2DParam.create(height=200, width=200, sigma=20)
107+
img = create_image_from_param(param)
108+
panel.add_object(img)
109+
110+
# Run centroid analysis to create results and store analysis parameters
111+
execenv.print(" Running centroid analysis...")
112+
with Conf.proc.show_result_dialog.temp(False):
113+
panel.processor.run_feature("centroid")
114+
115+
# Verify that analysis parameters exist
116+
img_refreshed = panel.objmodel[get_uuid(img)]
117+
analysis_params = extract_analysis_parameters(img_refreshed)
118+
assert analysis_params is not None, (
119+
"Analysis parameters should exist after running centroid"
120+
)
121+
assert analysis_params.func_name == "centroid", (
122+
"Analysis parameters should store the centroid function name"
123+
)
124+
execenv.print(" ✓ Analysis parameters stored")
125+
126+
# Delete all results
127+
execenv.print(" Deleting all results...")
128+
panel.objview.select_objects([get_uuid(img)])
129+
panel.delete_results()
130+
131+
# Verify that analysis parameters were also cleared
132+
img_after = panel.objmodel[get_uuid(img)]
133+
analysis_params_after = extract_analysis_parameters(img_after)
134+
assert analysis_params_after is None, (
135+
"Analysis parameters should be cleared after deleting results"
136+
)
137+
execenv.print(" ✓ Analysis parameters cleared")
138+
139+
# Now add a ROI and verify no auto-recompute happens (no new results)
140+
execenv.print(" Adding ROI to verify no auto-recompute...")
141+
roi = create_image_roi("rectangle", [25, 25, 100, 100])
142+
img_after.roi = roi
143+
panel.processor.auto_recompute_analysis(img_after)
144+
145+
# Verify that no new results were created
146+
adapter_after_roi = GeometryAdapter.from_obj(img_after, "centroid")
147+
assert adapter_after_roi is None, (
148+
"No centroid result should be created after ROI change "
149+
"because analysis parameters were cleared"
150+
)
151+
execenv.print(
152+
" ✓ No auto-recompute after ROI change (analysis params cleared)"
153+
)
154+
execenv.print("\n✓ All tests passed!")
155+
156+
94157
if __name__ == "__main__":
95158
test_delete_results_image()
96159
test_delete_results_signal()
160+
test_delete_results_clears_analysis_parameters()

doc/locale/fr/LC_MESSAGES/release_notes/release_1.00.po

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ msgid ""
77
msgstr ""
88
"Project-Id-Version: DataLab \n"
99
"Report-Msgid-Bugs-To: \n"
10-
"POT-Creation-Date: 2025-12-16 10:16+0100\n"
10+
"POT-Creation-Date: 2025-12-16 10:56+0100\n"
1111
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1212
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1313
"Language: fr\n"
@@ -27,6 +27,21 @@ msgstr ""
2727
msgid "🛠️ Bug Fixes since version 1.0.2"
2828
msgstr "🛠️ Correctifs depuis la version 1.0.2"
2929

30+
msgid "**Analysis auto-recompute - Stale parameters after deleting results:**"
31+
msgstr "**Recalcul automatique de l'analyse - Paramètres obsolètes après suppression des résultats :**"
32+
33+
msgid "Fixed analysis parameters not being cleared when deleting analysis results, which could cause unexpected auto-recompute behavior when modifying ROIs"
34+
msgstr "Correction des paramètres d'analyse qui n'étaient pas effacés lors de la suppression des résultats, ce qui pouvait provoquer un comportement de recalcul automatique inattendu lors de la modification des ROI"
35+
36+
msgid "After deleting results (via \"Delete all results\" or individual result deletion), changing the ROI would trigger recomputation of the deleted analysis because the stored parameters remained in object metadata"
37+
msgstr "Après la suppression des résultats (via « Supprimer tous les résultats » ou suppression individuelle), la modification de la ROI déclenchait le recalcul de l'analyse supprimée car les paramètres restaient dans les métadonnées de l'objet"
38+
39+
msgid "The fix ensures analysis parameters are properly cleared alongside the results, preventing unwanted automatic recomputation"
40+
msgstr "Le correctif assure que les paramètres d'analyse sont correctement effacés avec les résultats, empêchant le recalcul automatique indésirable"
41+
42+
msgid "This closes [Issue #285](https://github.com/DataLab-Platform/DataLab/issues/285) - Analysis parameters not cleared after deleting results"
43+
msgstr "Ceci clôture [Issue #285](https://github.com/datalab-platform/datalab/issues/285) - Analysis parameters not cleared after deleting results"
44+
3045
msgid "**Backwards-drawn rectangular ROI causes NaN statistics:**"
3146
msgstr "**ROI rectangulaire dessinée à l'envers cause des statistiques NaN :**"
3247

doc/release_notes/release_1.00.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44

55
### 🛠️ Bug Fixes since version 1.0.2 ###
66

7+
**Analysis auto-recompute - Stale parameters after deleting results:**
8+
9+
* Fixed analysis parameters not being cleared when deleting analysis results, which could cause unexpected auto-recompute behavior when modifying ROIs
10+
* After deleting results (via "Delete all results" or individual result deletion), changing the ROI would trigger recomputation of the deleted analysis because the stored parameters remained in object metadata
11+
* The fix ensures analysis parameters are properly cleared alongside the results, preventing unwanted automatic recomputation
12+
* This closes [Issue #285](https://github.com/DataLab-Platform/DataLab/issues/285) - Analysis parameters not cleared after deleting results
13+
714
**Backwards-drawn rectangular ROI causes NaN statistics:**
815

916
* Fixed rectangular ROI statistics returning NaN values when the ROI was drawn "backwards" (from bottom-right to top-left instead of top-left to bottom-right)

0 commit comments

Comments
 (0)