Skip to content

Commit

Permalink
Fix bug where one missing index.json caused no ensembles to be loaded
Browse files Browse the repository at this point in the history
This is not without pitfalls, as the missing ensemble could be related to
an ensemble that still exists.
  • Loading branch information
oyvindeide committed Feb 8, 2024
1 parent c1815d3 commit dddf883
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/ert/storage/local_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit dddf883

Please sign in to comment.