Skip to content

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

fix(workflows): reject malformed workflow config on remove (#4096)

Marsel Safin0e6124ac6450
diff --git a/src/specify_cli/workflows/catalog.py b/src/specify_cli/workflows/catalog.py
index 61f490631..028fce74d 100644
--- a/src/specify_cli/workflows/catalog.py
+++ b/src/specify_cli/workflows/catalog.py
@@ -784,12 +784,14 @@ class WorkflowCatalog:
raise WorkflowValidationError("No 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 WorkflowValidationError(
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 WorkflowValidationError(
"Catalog config file is corrupted (expected a mapping)."
)
diff --git a/tests/test_workflows.py b/tests/test_workflows.py
index d599f3c6a..cb663f8ca 100644
--- a/tests/test_workflows.py
+++ b/tests/test_workflows.py
@@ -8409,6 +8409,18 @@ class TestWorkflowCatalog:
with pytest.raises(WorkflowValidationError, 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 WorkflowCatalog, WorkflowValidationError
+
+ config_path = project_dir / ".specify" / "workflow-catalogs.yml"
+ config_path.write_text(yaml.safe_dump(bad), encoding="utf-8")
+
+ with pytest.raises(WorkflowValidationError, match="expected a mapping"):
+ WorkflowCatalog(project_dir).remove_catalog(0)
+
def test_get_catalog_configs(self, project_dir):
from specify_cli.workflows.catalog import WorkflowCatalog