aiidateam / aiida-core

The official repository for the AiiDA code
https://aiida-core.readthedocs.io
Other
437 stars 193 forks source link

`orm.PortableCode` doesn't have `filepath_files` attribute? #6568

Closed GeigerJ2 closed 1 month ago

GeigerJ2 commented 2 months ago

As the title says. I noticed this through the test_data_exporters function in tests/orm/nodes/data/test_data.py while working on #6565. Instantiation of an instance of orm.PortableCode works fine, but when _exportformat is called, the exception as shown below is thrown. Was filepath_formats intentionally not set as an attribute of orm.PortableCode (as compared to filepath_executable), or might this be a bug?

/home/geiger_j/aiida_projects/aiida-dev/git-repos/aiida-core.worktrees/refactor/code-export-prepare/tests/orm/nodes/data/test_data.py::test_data_exporters[data_plugin12] failed: data_plugin = <class 'aiida.orm.nodes.data.code.portable.PortableCode'>
generate_class_instance = <function generate_class_instance.<locals>._generate_class_instance at 0x7a3d0cbdec20>

    def test_data_exporters(data_plugin, generate_class_instance):
        """Verify that the return value of the export methods of all `Data` sub classes have the correct type.

        It should be a tuple where the first should be a byte string and the second a dictionary.
        """
        export_formats = data_plugin.get_export_formats()

        if not export_formats:
            return

        instance = generate_class_instance(data_plugin)

        for fileformat in export_formats:
>           content, dictionary = instance._exportcontent(fileformat)

tests/orm/nodes/data/test_data.py:181: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
src/aiida/orm/nodes/data/data.py:179: in _exportcontent
    string, dictionary = func(main_file_name=main_file_name, **kwargs)
src/aiida/orm/nodes/data/code/abstract.py:404: in _prepare_yaml
    return self._prepare_yml(main_file_name=main_file_name, *args, **kwargs)
src/aiida/orm/nodes/data/code/abstract.py:393: in _prepare_yml
    value = getattr(self, key).label if key == 'computer' else getattr(self, key)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <PortableCode: Local code '' pk: None, uuid: 8fed84bf-26e6-4a1e-ab34-44b0e638ccc4>
name = 'filepath_files'

    def __getattr__(self, name: str) -> Any:
        """This method is called when an attribute is not found in the instance.

        It allows for the handling of deprecated mixin methods.
        """
        if name in self._deprecated_extra_methods:
            new_name = self._deprecated_extra_methods[name]
            kls = self.__class__.__name__
            warn_deprecation(
                f'`{kls}.{name}` is deprecated, use `{kls}.base.extras.{new_name}` instead.', version=3, stacklevel=3
            )
            return getattr(self.base.extras, new_name)

        if name in self._deprecated_attr_methods:
            new_name = self._deprecated_attr_methods[name]
            kls = self.__class__.__name__
            warn_deprecation(
                f'`{kls}.{name}` is deprecated, use `{kls}.base.attributes.{new_name}` instead.',
                version=3,
                stacklevel=3,
            )
            return getattr(self.base.attributes, new_name)

        if name in self._deprecated_repo_methods:
            new_name = self._deprecated_repo_methods[name]
            kls = self.__class__.__name__
            warn_deprecation(
                f'`{kls}.{name}` is deprecated, use `{kls}.base.repository.{new_name}` instead.',
                version=3,
                stacklevel=3,
            )
            return getattr(self.base.repository, new_name)

        if name in self._deprecated_comment_methods:
            new_name = self._deprecated_comment_methods[name]
            kls = self.__class__.__name__
            warn_deprecation(
                f'`{kls}.{name}` is deprecated, use `{kls}.base.comments.{new_name}` instead.', version=3, stacklevel=3
            )
            return getattr(self.base.comments, new_name)

        if name in self._deprecated_caching_methods:
            new_name = self._deprecated_caching_methods[name]
            kls = self.__class__.__name__
            warn_deprecation(
                f'`{kls}.{name}` is deprecated, use `{kls}.base.caching.{new_name}` instead.', version=3, stacklevel=3
            )
            return getattr(self.base.caching, new_name)

        if name in self._deprecated_links_methods:
            new_name = self._deprecated_links_methods[name]
            kls = self.__class__.__name__
            warn_deprecation(
                f'`{kls}.{name}` is deprecated, use `{kls}.base.links.{new_name}` instead.', version=3, stacklevel=3
            )
            return getattr(self.base.links, new_name)

>       raise AttributeError(name)
E       AttributeError: filepath_files

src/aiida/orm/nodes/node.py:797: AttributeError
sphuber commented 2 months ago

It is not strictly a bug since, up to now, I don't think any code is relying on that property being there. But it is good to add it.

GeigerJ2 commented 1 month ago

Closing as it's not really a bug, and shouldn't be applicable anymore for #6565.