A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
handle rust panic errors when getting config for obstore (#8658)
Shahmir Varqhabd527bfb23a2
diff --git a/marimo/_data/_external_storage/storage.py b/marimo/_data/_external_storage/storage.pyindex 6f5eba71e6..1fb0f94195 100644--- a/marimo/_data/_external_storage/storage.py+++ b/marimo/_data/_external_storage/storage.py@@ -25,7 +25,15 @@ if TYPE_CHECKING:AbstractFileSystem, # noqa: F401)from obstore import ObjectMeta- from obstore.store import ObjectStore # noqa: F401+ from obstore.store import (+ AzureConfig,+ AzureStore,+ GCSConfig,+ GCSStore,+ ObjectStore, # noqa: F401+ S3Config,+ S3Store,+ )LOGGER = _loggers.marimo_logger()@@ -136,6 +144,18 @@ class Obstore(StorageBackend["ObjectStore"]):LOGGER.info("Failed to sign URL for %s", path)return None+ def _get_config(+ self, store: AzureStore | GCSStore | S3Store+ ) -> AzureConfig | GCSConfig | S3Config | None:+ try:+ return store.config+ except BaseException:+ # Sometimes, there will be a Rust panic when trying to get the config for invalid stores+ LOGGER.exception(+ "Failed to read store config for %s", type(store).__name__+ )+ return None+@propertydef protocol(self) -> KNOWN_STORAGE_TYPES | str:from obstore.store import (@@ -149,7 +169,11 @@ class Obstore(StorageBackend["ObjectStore"]):# Try the endpoint URL which can give a more accurate protocolif not isinstance(self.store, (MemoryStore, HTTPStore, LocalStore)):- endpoint = self.store.config.get("endpoint")+ config = self._get_config(self.store)+ if config is None:+ return "unknown"++ endpoint = config.get("endpoint")if isinstance(endpoint, str) and (protocol := detect_protocol_from_url(endpoint)):@@ -189,7 +213,10 @@ class Obstore(StorageBackend["ObjectStore"]):if isinstance(self.store, LocalStore):return None # root- config = self.store.config+ config = self._get_config(self.store)+ if config is None:+ return None+bucket = config.get("bucket")if bucket is None:LOGGER.debug(diff --git a/tests/_data/_external_storage/test_storage_models.py b/tests/_data/_external_storage/test_storage_models.pyindex afedaa482b..f6be34f1e4 100644--- a/tests/_data/_external_storage/test_storage_models.py+++ b/tests/_data/_external_storage/test_storage_models.py@@ -524,6 +524,38 @@ class TestObstore:backend = self._make_backend(store)assert backend.display_name == "In-memory"+ def test_protocol_returns_unknown_when_config_panics(self) -> None:+ from obstore.store import S3Store++ store = S3Store("bucket", skip_signature=True)+ backend = self._make_backend(store)++ def _raise(_: Any) -> None:+ raise BaseException("rust panic") # noqa: TRY002++ with patch.object(+ type(store),+ "config",+ new_callable=lambda: property(_raise),+ ):+ assert backend.protocol == "unknown"++ def test_root_path_returns_none_when_config_panics(self) -> None:+ from obstore.store import S3Store++ store = S3Store("bucket", skip_signature=True)+ backend = self._make_backend(store)++ def _raise(_: Any) -> None:+ raise BaseException("rust panic") # noqa: TRY002++ with patch.object(+ type(store),+ "config",+ new_callable=lambda: property(_raise),+ ):+ assert backend.root_path is None+@pytest.mark.skipif(not HAS_FSSPEC, reason="fsspec not installed")class TestFsspecFilesystem: