@@ -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+
11981223def 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