From 3df5ab7f267e06dee1d6a46e001da01825735f4d Mon Sep 17 00:00:00 2001 From: Zohar Malamant Date: Thu, 31 Aug 2023 15:43:02 +0200 Subject: [PATCH] Properly load index.json before migrating --- src/ert/storage/local_storage.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/ert/storage/local_storage.py b/src/ert/storage/local_storage.py index 6d8c01acd04..eed6acb983c 100644 --- a/src/ert/storage/local_storage.py +++ b/src/ert/storage/local_storage.py @@ -1,6 +1,5 @@ from __future__ import annotations -import json import logging import os import sys @@ -172,7 +171,8 @@ def __init__( self.path = Path(path) if not ignore_migration_check: try: - version = _storage_version(self.path) + self._index = _storage_index(self.path) + version = self._index.version if version == 0: from ert.storage.migration import block_fs # pylint: disable=C0415 @@ -290,17 +290,16 @@ def _load_ensemble(self, path: Path) -> LocalEnsembleAccessor: return LocalEnsembleAccessor(self, path) -def _storage_version(path: Path) -> Optional[int]: +def _storage_index(path: Path) -> _Index: if not path.exists(): - return None + return _Index() try: - with open(path / "index.json", encoding="utf-8") as f: - return int(json.load(f)["version"]) + return _Index.parse_file(path / "index.json") except KeyError as exc: raise NotImplementedError("Incompatible ERT Local Storage") from exc except FileNotFoundError: if _is_block_storage(path): - return 0 + return _Index(version=0) raise ValueError("Unknown storage version")