Skip to content

Infinite loop when iterating over group objects while adding new objects #274

@PierreRaybaut

Description

@PierreRaybaut

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

  1. Create a plugin that retrieves object IDs from a group using get_object_ids_from_group_title()
  2. Iterate over those IDs and add new objects to the panel during the loop
  3. 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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions