Skip to content

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

fix(workflows,extensions): tolerate non-list catalog tags in search/info display (#3770)

Noor ul ain8bfe6e14d16f
diff --git a/src/specify_cli/extensions/_commands.py b/src/specify_cli/extensions/_commands.py
index 80b7d2caf..f67a7fb4f 100644
--- a/src/specify_cli/extensions/_commands.py
+++ b/src/specify_cli/extensions/_commands.py
@@ -801,8 +801,9 @@ def extension_search(
# Metadata
console.print(f"\n [dim]Author:[/dim] {_escape_markup(str(ext.get('author', 'Unknown')))}")
- if ext.get('tags'):
- tags_str = ", ".join(str(t) for t in ext['tags'])
+ ext_tags = ext.get('tags', [])
+ if isinstance(ext_tags, list) and ext_tags:
+ tags_str = ", ".join(str(t) for t in ext_tags)
console.print(f" [dim]Tags:[/dim] {_escape_markup(tags_str)}")
# Source catalog
@@ -1025,8 +1026,9 @@ def _print_extension_info(ext_info: dict, manager):
console.print()
# Tags
- if ext_info.get('tags'):
- tags_str = ", ".join(str(t) for t in ext_info['tags'])
+ info_tags = ext_info.get('tags', [])
+ if isinstance(info_tags, list) and info_tags:
+ tags_str = ", ".join(str(t) for t in info_tags)
console.print(f"[bold]Tags:[/bold] {_escape_markup(tags_str)}")
console.print()
diff --git a/src/specify_cli/workflows/_commands.py b/src/specify_cli/workflows/_commands.py
index eaacb3489..818938d42 100644
--- a/src/specify_cli/workflows/_commands.py
+++ b/src/specify_cli/workflows/_commands.py
@@ -2326,7 +2326,7 @@ def workflow_search(
if desc:
console.print(f" {_escape_markup(str(desc))}")
tags = wf.get("tags", [])
- if tags:
+ if isinstance(tags, list) and tags:
safe_tags = _escape_markup(", ".join(str(t) for t in tags))
console.print(f" [dim]Tags: {safe_tags}[/dim]")
console.print()
@@ -2424,8 +2424,9 @@ def workflow_info(
console.print(f" Version: {_escape_markup(str(info.get('version', '?')))}")
if info.get("description"):
console.print(f" Description: {_escape_markup(str(info['description']))}")
- if info.get("tags"):
- safe_tags = _escape_markup(", ".join(str(t) for t in info["tags"]))
+ info_tags = info.get("tags", [])
+ if isinstance(info_tags, list) and info_tags:
+ safe_tags = _escape_markup(", ".join(str(t) for t in info_tags))
console.print(f" Tags: {safe_tags}")
console.print(" [yellow]Not installed[/yellow]")
else:
diff --git a/tests/test_extensions.py b/tests/test_extensions.py
index 4da73327e..44edca3d3 100644
--- a/tests/test_extensions.py
+++ b/tests/test_extensions.py
@@ -4412,6 +4412,44 @@ class TestExtensionCatalog:
results = catalog.search(query="jira")
assert {r["id"] for r in results} == {"jira"}
+ def test_search_and_info_tolerate_non_list_tags(self, temp_dir):
+ """A scalar ``tags:`` value must not crash the search/info display.
+
+ ``ExtensionCatalog.search`` guards its tag *filter* with
+ ``isinstance(raw_tags, list)``, but the ``extension search`` and
+ ``extension info`` display paths only tested truthiness before
+ iterating. ``tags: 5`` is truthy and not iterable, so both raised
+ ``TypeError: 'int' object is not iterable``.
+ """
+ from typer.testing import CliRunner
+ from unittest.mock import patch
+ from specify_cli import app
+
+ project_dir = temp_dir / "project"
+ project_dir.mkdir()
+ (project_dir / ".specify").mkdir()
+
+ merged = [{
+ "id": "jira",
+ "name": "Jira",
+ "version": "1.0.0",
+ "description": "Jira",
+ "tags": 5,
+ }]
+
+ with patch.object(ExtensionCatalog, "_get_merged_extensions", return_value=merged), \
+ patch("specify_cli.extensions._commands._require_specify_project",
+ return_value=project_dir):
+ searched = CliRunner().invoke(app, ["extension", "search", "Jira"])
+ info = CliRunner().invoke(app, ["extension", "info", "jira"])
+
+ assert searched.exit_code == 0, searched.output
+ assert "Jira" in searched.output
+ assert "Tags:" not in searched.output
+
+ assert info.exit_code == 0, info.output
+ assert "Tags:" not in info.output
+
def test_search_tolerates_non_string_author_and_name(self, temp_dir):
"""Non-string catalog author/name must not crash author/query search.
diff --git a/tests/test_workflows.py b/tests/test_workflows.py
index 61c625a39..e147f6dd7 100644
--- a/tests/test_workflows.py
+++ b/tests/test_workflows.py
@@ -10560,6 +10560,44 @@ steps:
assert "desc [with] brackets" in result.output
assert "tag[1]" in result.output
+ def test_search_and_info_tolerate_non_list_tags(self, project_dir, monkeypatch):
+ """A scalar ``tags:`` value must not crash the search/info display.
+
+ ``WorkflowCatalog.search`` guards its tag *filter* with
+ ``isinstance(raw_tags, list)``, but the ``workflow search`` and
+ ``workflow info`` display paths only tested truthiness before
+ iterating. ``tags: 5`` is truthy and not iterable, so both raised
+ ``TypeError: 'int' object is not iterable``.
+ """
+ from typer.testing import CliRunner
+ from specify_cli import app
+ from specify_cli.workflows.catalog import WorkflowCatalog
+
+ monkeypatch.chdir(project_dir)
+ workflows = {
+ "wf-a": {
+ "name": "Workflow A",
+ "version": "1.0.0",
+ "description": "desc",
+ "tags": 5,
+ },
+ }
+ monkeypatch.setattr(
+ WorkflowCatalog,
+ "_get_merged_workflows",
+ lambda self, force_refresh=False: {k: dict(v) for k, v in workflows.items()},
+ )
+ runner = CliRunner()
+ searched = runner.invoke(app, ["workflow", "search"])
+ info = runner.invoke(app, ["workflow", "info", "wf-a"])
+
+ assert searched.exit_code == 0, searched.output
+ assert "Workflow A" in searched.output
+ assert "Tags:" not in searched.output
+
+ assert info.exit_code == 0, info.output
+ assert "Tags:" not in info.output
+
def test_catalog_list_escapes_rich_markup(self, project_dir, monkeypatch):
"""User-editable catalog name/url/description must not be parsed as Rich markup."""
from typer.testing import CliRunner