diff --git a/CHANGELOG.md b/CHANGELOG.md index 219422bb9..2331deda2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ - Improve HTML rendering of tables. @bendichter [#998](https://github.com/hdmf-dev/hdmf/pull/998) - Improved issue and PR templates. @rly [#1004](https://github.com/hdmf-dev/hdmf/pull/1004) +### Bug fixes +- Fixed issue with custom class generation when a spec has a `name`. @rly [#1006](https://github.com/hdmf-dev/hdmf/pull/1006) + ## HDMF 3.11.0 (October 30, 2023) ### Enhancements diff --git a/src/hdmf/build/classgenerator.py b/src/hdmf/build/classgenerator.py index 6a31f4cec..bdfbbc7da 100644 --- a/src/hdmf/build/classgenerator.py +++ b/src/hdmf/build/classgenerator.py @@ -225,8 +225,8 @@ def process_field_spec(cls, classdict, docval_args, parent_cls, attr_name, not_i fixed_value = getattr(field_spec, 'value', None) if fixed_value is not None: fields_conf['settable'] = False - if isinstance(field_spec, (BaseStorageSpec, LinkSpec)) and field_spec.data_type is not None: - # subgroups, datasets, and links with data types can have fixed names + if isinstance(field_spec, BaseStorageSpec) and field_spec.data_type is not None: + # subgroups and datasets with data types can have fixed names fixed_name = getattr(field_spec, 'name', None) if fixed_name is not None: fields_conf['required_name'] = fixed_name diff --git a/src/hdmf/spec/spec.py b/src/hdmf/spec/spec.py index f383fd34a..cdc041c7b 100644 --- a/src/hdmf/spec/spec.py +++ b/src/hdmf/spec/spec.py @@ -816,11 +816,6 @@ def data_type_inc(self): ''' The data type of target specification ''' return self.get(_target_type_key) - @property - def data_type(self): - ''' The data type of target specification ''' - return self.get(_target_type_key) - def is_many(self): return self.quantity not in (1, ZERO_OR_ONE) diff --git a/tests/unit/build_tests/test_classgenerator.py b/tests/unit/build_tests/test_classgenerator.py index 5635b12d1..0c117820b 100644 --- a/tests/unit/build_tests/test_classgenerator.py +++ b/tests/unit/build_tests/test_classgenerator.py @@ -497,7 +497,7 @@ def setUp(self): ], links=[ LinkSpec( - doc='A composition inside with a fixed name', + doc='A composition inside without a fixed name', name="my_baz1_link", target_type='Baz1' ), @@ -517,7 +517,7 @@ def test_gen_parent_class(self): {'name': 'name', 'type': str, 'doc': 'the name of this container'}, {'name': 'my_baz1', 'doc': 'A composition inside with a fixed name', 'type': baz1_cls}, {'name': 'my_baz2', 'doc': 'A composition inside with a fixed name', 'type': baz2_cls}, - {'name': 'my_baz1_link', 'doc': 'A composition inside with a fixed name', 'type': baz1_cls}, + {'name': 'my_baz1_link', 'doc': 'A composition inside without a fixed name', 'type': baz1_cls}, )) def test_init_fields(self): @@ -537,8 +537,7 @@ def test_init_fields(self): }, { 'name': 'my_baz1_link', - 'doc': 'A composition inside with a fixed name', - 'required_name': 'my_baz1_link' + 'doc': 'A composition inside without a fixed name', }, )) @@ -548,7 +547,7 @@ def test_set_field(self): baz3_cls = self.type_map.get_dt_container_cls('Baz3', CORE_NAMESPACE) baz1 = baz1_cls(name="my_baz1") baz2 = baz2_cls(name="my_baz2") - baz1_link = baz1_cls(name="my_baz1_link") + baz1_link = baz1_cls(name="any_name") baz3 = baz3_cls(name="test", my_baz1=baz1, my_baz2=baz2, my_baz1_link=baz1_link) self.assertEqual(baz3.my_baz1, baz1) self.assertEqual(baz3.my_baz2, baz2) @@ -573,13 +572,6 @@ def test_set_field_bad(self): with self.assertRaisesWith(ValueError, msg): baz3_cls(name="test", my_baz1=baz1, my_baz2=baz2, my_baz1_link=baz1_link) - baz1 = baz1_cls(name="my_baz1") - baz2 = baz2_cls(name="my_baz2") - baz1_link = baz1_cls(name="test") - msg = "Field 'my_baz1_link' on Baz3 must be named 'my_baz1_link'." - with self.assertRaisesWith(ValueError, msg): - baz3_cls(name="test", my_baz1=baz1, my_baz2=baz2, my_baz1_link=baz1_link) - class TestGetClassSeparateNamespace(TestCase): @@ -1049,7 +1041,7 @@ def test_process_field_spec_link(self): spec=GroupSpec('dummy', 'doc') ) - expected = {'__fields__': [{'name': 'attr3', 'doc': 'a link', 'required_name': 'attr3'}]} + expected = {'__fields__': [{'name': 'attr3', 'doc': 'a link'}]} self.assertDictEqual(classdict, expected) def test_post_process_fixed_name(self):