Skip to content

Commit 7534db0

Browse files
rowanwalker96claude
andcommitted
Never let a visit config disturb processing
The config lookup was unguarded: load_visit_config handles an unreadable file or bad settings itself, but resolve() does not, and any unexpected failure would have propagated out of the trigger. Wrap finding, reading and applying the config in one try per trigger. The settings are seeded from the recipe's own parameters first, so a failure leaves those in force, and the `enabled` gate moves outside the try with None meaning "the config did not say", which keeps the allow-list as the fallback. A visit off the allow-list therefore still refuses to run when its config cannot be read. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent bdb4b9c commit 7534db0

1 file changed

Lines changed: 53 additions & 15 deletions

File tree

‎src/dlstbx/services/trigger_xchem.py‎

Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -435,16 +435,28 @@ def trigger_modelbuilding(
435435
)
436436
return {"success": True}
437437

438-
# Per-visit settings, for anything the recipe did not set explicitly
439-
config = load_visit_config(xchem_visit_dir, self.log)
440-
if not (allow_listed if config.enabled is None else config.enabled):
438+
# Per-visit settings, for anything the recipe did not set explicitly.
439+
# A config that cannot be read must not disturb processing, so the
440+
# recipe's own parameters stand and the allow-list decides on its own.
441+
comparator_threshold = parameters.comparator_threshold
442+
pipedream = parameters.pipedream
443+
enabled = None
444+
try:
445+
config = load_visit_config(xchem_visit_dir, self.log)
446+
enabled = config.enabled
447+
comparator_threshold = config.resolve("comparator_threshold", parameters)
448+
pipedream = config.resolve("pipedream", parameters)
449+
except Exception:
450+
self.log.warning(
451+
f"Ignoring visit config for {xchem_visit_dir}", exc_info=True
452+
)
453+
454+
if not (allow_listed if enabled is None else enabled):
441455
self.log.info(
442456
f"Exiting PanDDA2/Pipedream trigger: autoprocessing is disabled in "
443457
f"the config for visit {xchem_visit_dir}"
444458
)
445459
return {"success": True}
446-
comparator_threshold = config.resolve("comparator_threshold", parameters)
447-
pipedream = config.resolve("pipedream", parameters)
448460

449461
# Industrial proposals never run Pipedream, whatever the visit asks for
450462
if industrial and pipedream:
@@ -900,17 +912,29 @@ def trigger_hitidentification(
900912
# Re-derive paths from labxchem visit parameter
901913
xchem_visit_dir = pathlib.Path(parameters.xchem_visit_directory)
902914

903-
# Per-visit settings, for anything the recipe did not set explicitly
904-
config = load_visit_config(xchem_visit_dir, self.log)
905-
if config.enabled is False:
915+
# Per-visit settings, for anything the recipe did not set explicitly.
916+
# A config that cannot be read must not disturb processing, so the
917+
# recipe's own parameters stand.
918+
comparator_threshold = parameters.comparator_threshold
919+
pipedream = parameters.pipedream
920+
pandda = parameters.pandda
921+
enabled = None
922+
try:
923+
config = load_visit_config(xchem_visit_dir, self.log)
924+
enabled = config.enabled
925+
comparator_threshold = config.resolve("comparator_threshold", parameters)
926+
pipedream = config.resolve("pipedream", parameters)
927+
except Exception:
928+
self.log.warning(
929+
f"Ignoring visit config for {xchem_visit_dir}", exc_info=True
930+
)
931+
932+
if enabled is False:
906933
self.log.info(
907934
f"Exiting hitidentification trigger: autoprocessing is disabled in "
908935
f"the config for visit {xchem_visit_dir}"
909936
)
910937
return {"success": True}
911-
comparator_threshold = config.resolve("comparator_threshold", parameters)
912-
pipedream = config.resolve("pipedream", parameters)
913-
pandda = parameters.pandda
914938

915939
# Industrial proposals never run Pipedream, whatever the visit asks for
916940
if (
@@ -1252,18 +1276,32 @@ def trigger_xchem_collate(
12521276
self.log.debug("XChemCollate trigger: Starting")
12531277

12541278
xchem_visit_dir = pathlib.Path(parameters.xchem_visit_directory)
1255-
config = load_visit_config(xchem_visit_dir, self.log)
1256-
if config.enabled is False:
1279+
1280+
# Per-visit settings, for anything the recipe did not set explicitly.
1281+
# A config that cannot be read must not disturb processing, so the
1282+
# recipe's own parameters stand.
1283+
pipedream = parameters.pipedream
1284+
notify_email = None
1285+
enabled = None
1286+
try:
1287+
config = load_visit_config(xchem_visit_dir, self.log)
1288+
enabled = config.enabled
1289+
pipedream = config.resolve("pipedream", parameters)
1290+
notify_email = config.notify
1291+
except Exception:
1292+
self.log.warning(
1293+
f"Ignoring visit config for {xchem_visit_dir}", exc_info=True
1294+
)
1295+
1296+
if enabled is False:
12571297
self.log.info(
12581298
f"Exiting XChemCollate trigger: autoprocessing is disabled in the "
12591299
f"config for visit {xchem_visit_dir}"
12601300
)
12611301
return {"success": True}
1262-
pipedream = config.resolve("pipedream", parameters)
12631302

12641303
# Who gets the finished-processing mail: whoever the visit config names,
12651304
# else the visit's ISPyB Team Leader.
1266-
notify_email = config.notify
12671305
if notify_email:
12681306
self.log.info(f"Notifying {notify_email} from the config for {visit}")
12691307
else:

0 commit comments

Comments
 (0)