From 4b463761a6c5190ce50890b0ba5c9e56847b71b6 Mon Sep 17 00:00:00 2001 From: Manasa Venkatakrishnan <14958785+manasaV3@users.noreply.github.com> Date: Mon, 4 Nov 2024 13:21:51 -0800 Subject: [PATCH] chore: Handle no neuroglancer config file (#339) * Handle no neuroglancer config file * Handling for api v2 * Fix tests --- apiv2/db_import/importers/tomogram.py | 6 +++++- ingestion_tools/scripts/importers/db/tomogram.py | 6 ++++-- .../scripts/tests/db_import/test_db_tomo_import.py | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/apiv2/db_import/importers/tomogram.py b/apiv2/db_import/importers/tomogram.py index 22b67227e..28d0af45d 100644 --- a/apiv2/db_import/importers/tomogram.py +++ b/apiv2/db_import/importers/tomogram.py @@ -34,7 +34,11 @@ class TomogramItem(ItemDBImporter): def normalize_to_unknown_str(self, value: str) -> str: return value.replace(" ", "_") if value else "Unknown" - def generate_neuroglancer_data(self, path) -> str: + def generate_neuroglancer_data(self, path) -> str | None: + if not path: + # Handle the case where there is no neuroglancer config file specified which is expected when + # visualization_default is set to False. + return None config = self.config.load_key_json(path, is_file_required=False) # TODO: Log warning return json.dumps(config, separators=(",", ":")) if config else "{}" diff --git a/ingestion_tools/scripts/importers/db/tomogram.py b/ingestion_tools/scripts/importers/db/tomogram.py index 0396ee9ca..1c3795bb0 100644 --- a/ingestion_tools/scripts/importers/db/tomogram.py +++ b/ingestion_tools/scripts/importers/db/tomogram.py @@ -72,9 +72,11 @@ def get_tomogram_type(self) -> str: return "CANONICAL" return "UNKOWN" # TYPO that's also reflected in the db :'( - def generate_neuroglancer_data(self, config_path) -> str: + def generate_neuroglancer_data(self, config_path) -> str | None: if not config_path: - return "{}" + # Handle the case where there is no neuroglancer config file specified, which is expected when + # visualization_default is set to False. + return None config = self.config.load_key_json(config_path, is_file_required=True) # TODO: Log warning return json.dumps(config, separators=(",", ":")) if config else "{}" diff --git a/ingestion_tools/scripts/tests/db_import/test_db_tomo_import.py b/ingestion_tools/scripts/tests/db_import/test_db_tomo_import.py index 3cef1ea82..383706431 100644 --- a/ingestion_tools/scripts/tests/db_import/test_db_tomo_import.py +++ b/ingestion_tools/scripts/tests/db_import/test_db_tomo_import.py @@ -120,7 +120,7 @@ def expected_tomograms_by_run(http_prefix: str) -> dict[str, dict[float, list[di "offset_x": 0, "offset_y": 0, "offset_z": 0, - "neuroglancer_config": "{}", + "neuroglancer_config": None, "type": "CANONICAL", "deposition_id": 300, }