diff --git a/src/aiida/orm/nodes/data/code/abstract.py b/src/aiida/orm/nodes/data/code/abstract.py index 812d111ae..72c0a48d8 100644 --- a/src/aiida/orm/nodes/data/code/abstract.py +++ b/src/aiida/orm/nodes/data/code/abstract.py @@ -11,6 +11,7 @@ from __future__ import annotations import abc +import contextlib import functools import pathlib import typing as t @@ -382,23 +383,24 @@ def get_builder(self) -> 'ProcessBuilder': return builder - def _prepare_yml(self, *args, **kwargs): - """Export code to a yml file.""" + def _prepare_yaml(self, *args, **kwargs): + """Export code to a YAML file.""" import yaml code_data = {} sort = kwargs.get('sort', False) for key in self.Model.model_fields.keys(): - value = getattr(self, key).label if key == 'computer' else getattr(self, key) + with contextlib.suppress(AttributeError): + value = getattr(self, key).label if key == 'computer' else getattr(self, key) - # If the attribute is not set, for example ``with_mpi`` do not export it, so that there are no null-values - # in the resulting YAML file - if value is not None: - code_data[key] = str(value) + # If the attribute is not set, for example ``with_mpi`` do not export it + # so that there are no null-values in the resulting YAML file + if value is not None: + code_data[key] = str(value) return yaml.dump(code_data, sort_keys=sort, encoding='utf-8'), {} - def _prepare_yaml(self, *args, **kwargs): + def _prepare_yml(self, *args, **kwargs): """Also allow for export as .yaml""" - return self._prepare_yml(*args, **kwargs) + return self._prepare_yaml(*args, **kwargs)