From e1818ed0e082e0dc084e8f3dc00c71e5da21d36f Mon Sep 17 00:00:00 2001 From: sapunyangkut <302607731+sapunyangkut@users.noreply.github.com> Date: Mon, 13 Jul 2026 00:24:35 +0800 Subject: [PATCH] fix: preserve string types in schema builder Signed-off-by: sapunyangkut <302607731+sapunyangkut@users.noreply.github.com> --- nf_core/pipelines/schema.py | 18 +++--------------- tests/pipelines/test_schema.py | 17 ++++++++++++++--- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/nf_core/pipelines/schema.py b/nf_core/pipelines/schema.py index c9b5558f23..731ee99d3b 100644 --- a/nf_core/pipelines/schema.py +++ b/nf_core/pipelines/schema.py @@ -933,21 +933,9 @@ def build_schema_param(self, p_val): if isinstance(p_val, float): return {"type": "number", "default": p_val} - # TODO: remove string branch once old text-format config caches are no longer supported - p_val = p_val.strip("\"'") - if not p_val or p_val == "null": - return {"type": "string"} - if p_val in ("true", "True"): - return {"type": "boolean", "default": True} - if p_val in ("false", "False"): - return {"type": "boolean"} - try: - num = float(p_val) - if num == int(num): - return {"type": "integer", "default": int(num)} - return {"type": "number", "default": num} - except ValueError: - return {"type": "string", "default": p_val} + if isinstance(p_val, str): + return {"type": "string", "default": p_val} if p_val else {"type": "string"} + raise TypeError(f"Unsupported schema parameter type: {type(p_val).__name__}") def launch_web_builder(self): """ diff --git a/tests/pipelines/test_schema.py b/tests/pipelines/test_schema.py index bc5600f6e2..a205b95cd2 100644 --- a/tests/pipelines/test_schema.py +++ b/tests/pipelines/test_schema.py @@ -19,6 +19,17 @@ from ..utils import with_temporary_file, with_temporary_folder +@pytest.mark.parametrize("value", ["3", "12.34", "true", "false", "null", "text", "", "'3'", '"3"']) +def test_build_schema_param_preserves_string_type(value): + param = nf_core.pipelines.schema.PipelineSchema().build_schema_param(value) + assert param == ({"type": "string", "default": value} if value else {"type": "string"}) + + +def test_build_schema_param_rejects_unknown_type(): + with pytest.raises(TypeError, match="Unsupported schema parameter type: list"): + nf_core.pipelines.schema.PipelineSchema().build_schema_param([]) + + class TestSchema(unittest.TestCase): """Class for schema tests""" @@ -430,17 +441,17 @@ def test_build_schema_param_str(self): def test_build_schema_param_bool(self): """Build a new schema param from a config value (bool)""" - param = self.schema_obj.build_schema_param("True") + param = self.schema_obj.build_schema_param(True) assert param == {"type": "boolean", "default": True} def test_build_schema_param_int(self): """Build a new schema param from a config value (int)""" - param = self.schema_obj.build_schema_param("12") + param = self.schema_obj.build_schema_param(12) assert param == {"type": "integer", "default": 12} def test_build_schema_param_float(self): """Build a new schema param from a config value (float)""" - param = self.schema_obj.build_schema_param("12.34") + param = self.schema_obj.build_schema_param(12.34) assert param == {"type": "number", "default": 12.34} def test_build_schema(self):