Infinite loop when iterating over group objects while adding new objects
Description
When developing a DataLab plugin that iterates over object IDs from a group and adds new objects during the iteration, an infinite loop occurs.
Steps to Reproduce
- Create a plugin that retrieves object IDs from a group using
get_object_ids_from_group_title()
- Iterate over those IDs and add new objects to the panel during the loop
- The loop never terminates
Example code pattern that triggers the issue:
def compute_Fourier_forgroup(self, group) -> None:
sig_ids = self.get_object_ids_from_group_title(group)
for ids in sig_ids:
sign = self.main[ids]
# ... processing ...
FFT_sign = sips.fft(zsign)
self.signalpanel.add_object(FFT_sign) # Adding object causes infinite loop
Workaround
Wrapping the result with list() prevents the issue:
sig_ids = list(self.get_object_ids_from_group_title(group))
Root Cause
The ObjectGroup.get_object_ids() method in datalab/objectmodel.py returns a direct reference to its internal __objects list instead of a copy:
def get_object_ids(self) -> list[str]:
"""Return object ids in group"""
return self.__objects # Direct reference - problem!
When new objects are added to the group during iteration, the internal list grows, causing the iterator to never reach the end.
Solution
Return a copy of the list instead of the direct reference:
def get_object_ids(self) -> list[str]:
"""Return object ids in group"""
return list(self.__objects) # Safe copy
Impact
- Severity: High - causes application to hang
- Affected versions: All versions prior to fix
- Affected users: Plugin developers iterating over groups while adding objects
Infinite loop when iterating over group objects while adding new objects
Description
When developing a DataLab plugin that iterates over object IDs from a group and adds new objects during the iteration, an infinite loop occurs.
Steps to Reproduce
get_object_ids_from_group_title()Example code pattern that triggers the issue:
Workaround
Wrapping the result with
list()prevents the issue:Root Cause
The
ObjectGroup.get_object_ids()method indatalab/objectmodel.pyreturns a direct reference to its internal__objectslist instead of a copy:When new objects are added to the group during iteration, the internal list grows, causing the iterator to never reach the end.
Solution
Return a copy of the list instead of the direct reference:
Impact