From 3e8a635a95adfd13412e2089c587dfe32f1c1cb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Eide?= Date: Wed, 31 Jan 2024 12:42:05 +0100 Subject: [PATCH] Fix bug where one missing index.json caused no ensembles to be loaded This is not without pitfalls, as the missing ensemble could be related to an ensemble that still exists. --- src/ert/storage/local_storage.py | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/ert/storage/local_storage.py b/src/ert/storage/local_storage.py index 52411a0c580..a2fb153258d 100644 --- a/src/ert/storage/local_storage.py +++ b/src/ert/storage/local_storage.py @@ -118,22 +118,21 @@ def _load_index(self) -> _Index: @no_type_check def _load_ensembles(self): - try: - ensembles = [] - for ensemble_path in (self.path / "ensembles").iterdir(): + if not (self.path / "ensembles").exists(): + return {} + ensembles = [] + for ensemble_path in (self.path / "ensembles").iterdir(): + try: ensemble = self._load_ensemble(ensemble_path) ensembles.append(ensemble) - - # Make sure that the ensembles are sorted by name in reverse. Given - # multiple ensembles with a common name, iterating over the ensemble - # dictionary will yield the newest ensemble first. - ensembles = sorted(ensembles, key=lambda x: x.started_at, reverse=True) - return { - x.id: x - for x in sorted(ensembles, key=lambda x: x.started_at, reverse=True) - } - except FileNotFoundError: - return {} + except FileNotFoundError: + continue + # Make sure that the ensembles are sorted by name in reverse. Given + # multiple ensembles with a common name, iterating over the ensemble + # dictionary will yield the newest ensemble first. + return { + x.id: x for x in sorted(ensembles, key=lambda x: x.started_at, reverse=True) + } def _load_ensemble(self, path: Path) -> Any: return LocalEnsembleReader(self, path)