Skip to content

AttributeError in update_tree() when adding object via RemoteProxy #279

@PierreRaybaut

Description

@PierreRaybaut

AttributeError in update_tree() when adding object via RemoteProxy

Description

When running a macro that adds an object to DataLab via RemoteProxy.add_object(), an AttributeError: 'NoneType' object has no attribute 'setText' occurs in the update_tree() method of objectview.py.

Steps to Reproduce

  1. Start DataLab
  2. Add an image to the image panel
  3. Run a macro that processes the image and adds the result back via proxy:
from datalab.control.proxy import RemoteProxy
import sigima.objects
import sigima.proc.image as sipi

proxy = RemoteProxy()
proxy.select_image(1)
obj = proxy.get_object()
copy = obj.copy()

# Add circular ROI
copy.roi = sigima.objects.create_image_roi("circle", [50, 50, 20], inverse=True)

# Process and add result
result = sipi.denoise_bilateral(copy, sigma_color=0.05, sigma_spatial=2)
proxy.add_object(result)  # This crashes

Expected Behavior

The processed image with ROI should be added to the panel without errors.

Actual Behavior

The application crashes with the following traceback:

Traceback (most recent call last):
  File ".../panel/base.py", line 1550, in add_object
    objview.update_tree()
  File ".../gui/objectview.py", line 209, in update_tree
    item.setText(0, obj.short_id)
AttributeError: 'NoneType' object has no attribute 'setText'

Root Cause

The update_tree() method assumes all objects in the model have corresponding tree items. However, in rare edge cases (such as objects added via remote proxy with certain metadata configurations), the tree and model can become temporarily out of sync. When get_item_from_id() returns None, calling setText() on it causes the crash.

Solution

Make update_tree() defensive by checking if items exist before updating them. If an item is not found, call populate_tree() to rebuild the tree and ensure consistency between the tree and the model.

Environment

  • DataLab version: 1.0.3
  • Sigima version: 1.0.4
  • Python version: 3.9+
  • OS: Windows/Linux/macOS

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