Skip to content

Bidirectional DynamicTableRegion Links Cause RecursionError on Read #1371

@h-mayorquin

Description

@h-mayorquin

When two DynamicTable objects have DynamicTableRegion columns pointing to each other, HDMF encounters infinite recursion when reading the file:

RecursionError: maximum recursion depth exceeded
  File "hdmf/backends/hdf5/h5tools.py", line __read_ref
  File "hdmf/backends/hdf5/h5tools.py", line __read_group
  [... repeats infinitely ...]

Minimal example:

import tempfile
from pathlib import Path

from pynwb import NWBHDF5IO
from pynwb.testing.mock.file import mock_NWBFile
from pynwb.testing.mock.ecephys import mock_ElectrodeTable, mock_Units

nwbfile = mock_NWBFile()
mock_ElectrodeTable(n_rows=3, nwbfile=nwbfile)
mock_Units(num_units=3, nwbfile=nwbfile)

nwbfile.units.add_column(name='electrode_ref', description='Reference to electrodes', data=[0, 1, 2], table=nwbfile.electrodes)
nwbfile.electrodes.add_column(name='unit_ref', description='Reference to units', data=[[i] for i in range(3)], table=nwbfile.units)

with tempfile.TemporaryDirectory() as tmpdir:
    nwb_path = Path(tmpdir) / 'test.nwb'

    with NWBHDF5IO(nwb_path, 'w') as io:
        io.write(nwbfile)

    # This will cause RecursionError
    with NWBHDF5IO(nwb_path, 'r') as io:
        io.read()

Writing actually works it is reading that fails as @rly mentioned.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions