Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mismatched fixed name and included name causes errors on read/validate #582

Closed
5 tasks done
rly opened this issue Apr 21, 2021 · 6 comments · Fixed by #1006
Closed
5 tasks done

Mismatched fixed name and included name causes errors on read/validate #582

rly opened this issue Apr 21, 2021 · 6 comments · Fixed by #1006
Labels
category: bug errors in the code or code behavior

Comments

@rly
Copy link
Contributor

rly commented Apr 21, 2021

Description

In HDMF currently, if a container child data type is defined with a fixed name and included as a subgroup of
some group, and the subgroup is specified with a different name, then after writing to disk, the subgroup keeps the fixed name rather than the subgroup name. The data cannot be read and validation fails.

Example:

groups:
- data_type_def: TypeA
  name: a
- data_type_def: TypeB
  groups:
  - data_type_inc: TypeA
    name: inner_a

In HDMF:

a = TypeA()  # a.name = 'a'
b = TypeB(name='b', inner_a=a)
b.inner_a  # returns a and a.name is still 'a'
with HDF5IO('test.h5', 'w') as io:
    io.write(b)  # no errors
with HDF5IO('test.h5', 'r') as io:
    read_b = io.read()  # fails, __init__: missing argument 'inner_a'
# test.h5 has subgroup named 'a'

Environment

Python Executable: Python
Python Version: Python 3.8
Operating System: Windows
HDMF Version: dev

Checklist

  • Have you ensured the bug was not already reported ?
  • Have you included a brief and descriptive title?
  • Have you included a clear description of the problem you are trying to solve?
  • Have you included a minimal code snippet that reproduces the issue you are encountering?
  • Have you checked our Contributing document?
@rly rly added the category: bug errors in the code or code behavior label Apr 21, 2021
@rly
Copy link
Contributor Author

rly commented Apr 21, 2021

This bug appears when users write NWB extensions and add name to both their data type definitions and included type specs, as in https://github.com/akshay-jaggi/ndx-photometry/

@alessandratrapani
Copy link

In catalystneuro/ndx-holographic-stimulation#7 we are defining new neurodata type following the best practice as in hdmf-dev/hdmf-schema-language#14
But if we get this error when trying to add a data type with a different name:

ValueError: Field 'site' on PatternedOptogeneticSeries must be named 'site'.

Schema:

- neurodata_type_def: PatternedOptogeneticStimulusSite
  neurodata_type_inc: OptogeneticStimulusSite
  doc: An extension of OptogeneticStimulusSite to include the geometrical representation
    for the stimulus.
  attributes:
  - name: effector
    dtype: text
    doc: Light-activated effector protein expressed by the targeted cell (eg. ChR2)
    required: false
- neurodata_type_def: PatternedOptogeneticSeries
  neurodata_type_inc: TimeSeries
  doc: An extension of OptogeneticSeries to include the spatial patterns for the photostimulation.
  links:
  - doc: link to the patterned stimulus site
    name: site
    target_type: PatternedOptogeneticStimulusSite

Example

        stim_site = PatternedOptogeneticStimulusSite(
            name="StimulusSite",
            device=device,
            description=site_description,
            excitation_lambda=stimulation_wavelenght,  # nm
            effector=effector,
            location=location,
        )
        self.nwbfile.add_ogen_site(stim_site)
        photostimulation = PatternedOptogeneticSeries(
            name=series_name,
            description=series_description,
            data=data,
            timestamps=timestamps,
            site=stim_site,
        )

The error occurs when using hdmf 3.11.0 and pynwb 2.5.0

@oruebel
Copy link
Contributor

oruebel commented Nov 30, 2023

I assume the error is related to the definition of the link with the fixed name site that points to PatternedOptogeneticStimulusSite. As far as I know, links should be allowed to have a different name than the target they point, but I'm not sure how this needs to be handled in the code. My guess that this may be a bug in the `get_class(..)' method. @rly what do you think?

@alessandratrapani
Copy link

Ah sorry, another important piece of information: this only happens using hdmf 3.11 not 3.10

@oruebel
Copy link
Contributor

oruebel commented Dec 2, 2023

Ah sorry, another important piece of information: this only happens using hdmf 3.11 not 3.10

Thanks for the additional info. Just a hunch, but my guess is that this may then be related to the bug fixes in this PR #800 that were release in 3.11. @rly thoughts?

@rly
Copy link
Contributor Author

rly commented Dec 4, 2023

Yes, that's a bug introduced in #800. Sorry about that. I'll work on a fix Monday/Tuesday.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: bug errors in the code or code behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants