Skip to content

Custom Signal Creation: AttributeError when creating signal from menu #269

@PierreRaybaut

Description

@PierreRaybaut

GitHub Issue: Custom Signal Creation Bug

Title

AttributeError when creating custom signal from menu

Labels

  • bug
  • signal processing

Description

Bug Report

Summary:
Creating a custom signal from the "Create" menu triggers an immediate AttributeError: 'NoneType' object has no attribute 'T'.

Steps to Reproduce:

  1. Launch DataLab
  2. Go to Signal panel
  3. Click "Create" menu → "Custom"
  4. The error occurs immediately

Expected Behavior:

  • A dialog should appear asking for signal parameters (size, xmin, xmax)
  • After confirmation, a curve editor should open
  • User can edit the curve points interactively
  • A custom signal is created successfully

Actual Behavior:
Application crashes with:

AttributeError: 'NoneType' object has no attribute 'T'

Root Cause:
When creating a custom signal from the menu, new_object() is called with edit=False (the default). This caused the setup_array() call to be skipped, leaving xyarray as None. Later, the code tried to access param.xyarray.T which failed.

Environment:

  • DataLab version: 1.0.1
  • Python version: [any]
  • OS: Windows/Linux/macOS

Solution Implemented

Fix

Added a check in datalab/gui/newobject.py (lines 125-128) to force edit=True for CustomSignalParam instances, ensuring the user dialogs are always shown and the array is properly initialized.

# CustomSignalParam requires edit mode to initialize the xyarray.
# Without this, if edit=False (the default in new_object), the setup_array
# call would be skipped, leaving xyarray as None, which would cause an
# AttributeError when trying to access param.xyarray.T later.
if isinstance(param, OrigCustomSignalParam):
    edit = True

Testing

Created comprehensive unit tests in datalab/tests/features/signal/custom_signal_bug_unit_test.py:

  • Test CustomSignalParam initialization
  • Test setup_array() functionality
  • Test generate_1d_data() behavior
  • Test the bug fix prevents the AttributeError

All tests pass (4/4), and all existing tests continue to pass.

Files Changed

  1. datalab/gui/newobject.py - Added fix to force edit mode for custom signals
  2. datalab/tests/features/signal/custom_signal_bug_unit_test.py - New test file
  3. CHANGELOG.md - Documented the bug fix

Verification

To verify the fix works:

  1. Launch DataLab with the fix applied
  2. Go to Signal panel
  3. Click "Create" menu → "Custom"
  4. First dialog appears asking for size, xmin, xmax
  5. After confirmation, second dialog with curve editor appears
  6. Edit the curve if desired
  7. Confirm to create the custom signal
  8. Custom signal is created successfully

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