Skip to content

Commit 1188137

Browse files
Added an additional guard clause to fix the bug that causes an IndexError while interacting with the plots in the FitPropertyBrowser widget (#40574)
### Description of work <!-- Please provide an outline and reasoning for the work. If there is no linked issue provide context. --> Closes #40426. <!-- One line per closed issue. --> <!-- If issue raised by user. Do not leak email addresses. **Report to:** [user name] --> ### To test: The error was reported by a user through the error reporter. It is hard to reproduce but the stack trace clearly identifies the line to fix. Co-authored-by: Waruna Priyankara J A Wickramasingha <[email protected]>
1 parent b563cb6 commit 1188137

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Added an additional guard clause to fix the bug that causes an IndexError while interacting with the plots in the ``FitPropertyBrowser`` widget.

qt/python/mantidqt/mantidqt/widgets/fitpropertybrowser/fitpropertybrowserplotinteraction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ def _shift_stored_prefixes(self, removed_prefix):
300300
:param removed_prefix: Prefix of the function removed e.g f0
301301
:return:
302302
"""
303-
if not self.guess_lines or removed_prefix[1] == len(self.guess_lines):
303+
if not self.guess_lines or (len(removed_prefix) < 2) or (removed_prefix[1] == len(self.guess_lines)):
304304
return
305305
for prefixed_function in reversed(list(self.guess_lines)):
306306
prefix_and_function = prefixed_function.split(".")

qt/python/mantidqt/mantidqt/widgets/test/test_fitpropertybrowserplotinteraction.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,14 @@ def test_remove_function_correctly_updates_stored_prefixed_functions(self):
170170

171171
self.assertEqual(list(self.browser_plot_interaction.guess_lines.keys()), ["f0.FlatBackground", "f1.GausOsc"])
172172

173+
def test_shift_stored_prefixes_returns_when_prefix_len_is_less_than_two(self):
174+
self.create_mock_guess_lines()
175+
self.setup_mock_fit_browser(
176+
workspace_creator=self.create_workspace2D, workspace_name="test_workspace", function=FULL_FUNCTION, function_prefix="f"
177+
)
178+
self.browser_plot_interaction.slot_for_function_removed()
179+
self.assertEqual(list(self.browser_plot_interaction.guess_lines.keys()), ["f0.FlatBackground", "f1.LinearBackground", "f2.GausOsc"])
180+
173181
def test_remove_function_correctly_removes_line(self):
174182
workspace_name = "test_workspace"
175183
prefix = "f1"

0 commit comments

Comments
 (0)