Skip to content

Commit e816146

Browse files
committed
support monitors without version
1 parent 5b89d1c commit e816146

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/aiida/engine/processes/calcjobs/calcjob.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ def _setup_version_info(self) -> dict[str, Any]:
647647
entry_point = monitor.base.attributes.get('entry_point')
648648
entry_point_string = format_entry_point_string('aiida.calculations.monitors', entry_point)
649649
monitor_version_info = self.runner.plugin_version_provider.get_version_info(entry_point_string)
650-
version_info['version'].setdefault('monitors', {})[key] = monitor_version_info['version']['plugin']
650+
version_info['version'].setdefault('monitors', {})[key] = monitor_version_info['version'].get('plugin')
651651

652652
cache_version_info = {}
653653

tests/engine/processes/calcjobs/test_calc_job.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,6 +1195,31 @@ def test_monitor_version(get_calcjob_builder):
11951195
assert node.base.attributes.get('version')['monitors'] == {'monitor': __version__}
11961196

11971197

1198+
def empty_monitor(node, transport):
1199+
"""Empty monitor that returns None and has no __version__ in its module."""
1200+
return None
1201+
1202+
1203+
def test_monitor_without_version(get_calcjob_builder, entry_points):
1204+
"""Test that monitors without version information don't cause a KeyError.
1205+
1206+
This test ensures that monitors from packages without a __version__ attribute
1207+
can be used without raising a KeyError when setting up version info.
1208+
"""
1209+
entry_points.add(empty_monitor, group='aiida.calculations.monitors', name='core.empty_monitor')
1210+
1211+
builder = get_calcjob_builder()
1212+
builder.monitors = {'monitor': orm.Dict({'entry_point': 'core.empty_monitor'})}
1213+
_, node = launch.run_get_node(builder)
1214+
1215+
# The monitor should be in the version info, but with None as the version
1216+
# since the module doesn't have __version__
1217+
assert 'monitors' in node.base.attributes.get('version')
1218+
assert 'monitor' in node.base.attributes.get('version')['monitors']
1219+
# The value should be None since the module doesn't have __version__
1220+
assert node.base.attributes.get('version')['monitors']['monitor'] is None
1221+
1222+
11981223
def monitor_skip_parse(node, transport, **kwargs):
11991224
"""Kill the job and skip the parsing of retrieved output files."""
12001225
return CalcJobMonitorResult(message='skip parsing', parse=False)

0 commit comments

Comments
 (0)