Skip to content

💫 Toolkit to help you get started with SDD or any other process!

fix(workflows): reject malformed step config on remove (#4095)

Marsel Safin381ae9f8c1a6
diff --git a/src/specify_cli/workflows/catalog.py b/src/specify_cli/workflows/catalog.py
index 028fce74d..f494848a0 100644
--- a/src/specify_cli/workflows/catalog.py
+++ b/src/specify_cli/workflows/catalog.py
@@ -1465,12 +1465,14 @@ class StepCatalog:
raise StepValidationError("No step catalog config file found.")
try:
- data = yaml.safe_load(config_path.read_text(encoding="utf-8")) or {}
+ data = yaml.safe_load(config_path.read_text(encoding="utf-8"))
except (yaml.YAMLError, OSError, UnicodeDecodeError) as exc:
raise StepValidationError(
f"Catalog config file is unreadable or malformed: {exc}"
) from exc
- if not isinstance(data, dict):
+ if data is None:
+ data = {}
+ elif not isinstance(data, dict):
raise StepValidationError(
"Catalog config file is corrupted (expected a mapping)."
)
diff --git a/tests/test_workflows.py b/tests/test_workflows.py
index cb663f8ca..686298611 100644
--- a/tests/test_workflows.py
+++ b/tests/test_workflows.py
@@ -9134,6 +9134,18 @@ class TestStepCatalog:
with pytest.raises(StepValidationError, match="out of range"):
catalog.remove_catalog(5)
+ @pytest.mark.parametrize("bad", [[], False, 0, ""])
+ def test_remove_catalog_rejects_falsy_non_mapping_config(
+ self, project_dir, bad
+ ):
+ from specify_cli.workflows.catalog import StepCatalog, StepValidationError
+
+ config_path = project_dir / ".specify" / "step-catalogs.yml"
+ config_path.write_text(yaml.safe_dump(bad), encoding="utf-8")
+
+ with pytest.raises(StepValidationError, match="expected a mapping"):
+ StepCatalog(project_dir).remove_catalog(0)
+
def test_remove_catalog_no_config(self, project_dir):
from specify_cli.workflows.catalog import StepCatalog, StepValidationError