From 805af68173d94ea9eccb84c2d52b6aea0293126a Mon Sep 17 00:00:00 2001 From: Ranjith Guggilla Date: Sun, 6 Dec 2026 00:49:13 -0600 Subject: [PATCH 1/2] fix(serverless): report invalid input instead of raising from validator constraints Skip schema constraints for missing or wrong-typed values so validation returns the errors already collected. Add regression tests for missing, invalid, and valid values. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- runpod/serverless/utils/rp_validator.py | 12 +++- .../test_utils/test_validate.py | 66 +++++++++++++++++++ 2 files changed, 75 insertions(+), 3 deletions(-) diff --git a/runpod/serverless/utils/rp_validator.py b/runpod/serverless/utils/rp_validator.py index 5a66e18e5..2d7c1d708 100644 --- a/runpod/serverless/utils/rp_validator.py +++ b/runpod/serverless/utils/rp_validator.py @@ -79,10 +79,16 @@ def _validate_input_against_schema(schema, validated_input, error_list): error_list, f"{key} should be {rules['type']} type, not {type(validated_input[key])}.", ) + # Constraints are written for the declared type, so a value + # of another type is reported once and not passed to them. + continue - # Check lambda constraints. - if "constraints" in rules and not rules["constraints"]( - validated_input.get(key) + # Check lambda constraints. A missing input has no value to check and + # was already reported as required or as a schema error. + if ( + key in validated_input + and "constraints" in rules + and not rules["constraints"](validated_input[key]) ): _add_error(error_list, CONSTRAINTS_ERROR.format(key)) diff --git a/tests/test_serverless/test_utils/test_validate.py b/tests/test_serverless/test_utils/test_validate.py index 603851303..98aacc46e 100644 --- a/tests/test_serverless/test_utils/test_validate.py +++ b/tests/test_serverless/test_utils/test_validate.py @@ -92,6 +92,72 @@ def test_validate_invalid_type(self): "x should be type, not .", result["errors"] ) + def test_validate_missing_required_input_with_constraints(self): + """ + A missing required input is reported without calling its constraints + """ + schema = { + "steps": {"type": int, "required": True, "constraints": lambda x: x > 0} + } + + result = rp_validator.validate({}, schema) + + self.assertEqual(result, {"errors": ["steps is a required input."]}) + + def test_validate_missing_default_with_constraints(self): + """ + An optional input with no default is reported without calling its constraints + """ + schema = { + "steps": {"type": int, "required": False, "constraints": lambda x: x > 0} + } + + result = rp_validator.validate({}, schema) + + self.assertEqual( + result, {"errors": ["Schema error, missing default value for steps."]} + ) + + def test_validate_invalid_type_with_constraints(self): + """ + A value of the wrong type is reported without calling the constraints + """ + for value in ("20", None, [20]): + with self.subTest(value=value): + constraints = Mock(side_effect=lambda x: x > 0) + schema = { + "steps": {"type": int, "required": True, "constraints": constraints} + } + + result = rp_validator.validate({"steps": value}, schema) + + self.assertEqual( + result, + { + "errors": [ + f"steps should be type, not {type(value)}." + ] + }, + ) + constraints.assert_not_called() + + def test_validate_constraints_receive_valid_value(self): + """ + Constraints still run on a value of the declared type + """ + schema = { + "steps": {"type": int, "required": True, "constraints": lambda x: x > 0} + } + + self.assertEqual( + rp_validator.validate({"steps": 20}, schema), + {"validated_input": {"steps": 20}}, + ) + self.assertEqual( + rp_validator.validate({"steps": 0}, schema), + {"errors": ["steps does not meet the constraints."]}, + ) + def test_validate_rules_not_dict(self): """ Tests validate with rules not dict From 7ee4cc741e44662e907b2c8f5337a9705051cf30 Mon Sep 17 00:00:00 2001 From: Ranjith Guggilla Date: Sun, 6 Dec 2026 01:02:22 -0600 Subject: [PATCH 2/2] docs: fix broken CI unit test badge Point the README badge and its link to the current ci.yml workflow. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 91c3740ad..7bcf0daf3 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [![PyPI Package](https://badge.fury.io/py/runpod.svg)](https://badge.fury.io/py/runpod) [![Downloads](https://static.pepy.tech/personalized-badge/runpod?period=total&units=international_system&left_color=grey&right_color=blue&left_text=downloads)](https://pepy.tech/project/runpod) -[![CI | Unit Tests](https://github.com/runpod/runpod-python/actions/workflows/CI-pytests.yml/badge.svg)](https://github.com/runpod/runpod-python/actions/workflows/CI-pytests.yml) +[![CI | Unit Tests](https://github.com/runpod/runpod-python/actions/workflows/ci.yml/badge.svg)](https://github.com/runpod/runpod-python/actions/workflows/ci.yml) [![License](https://img.shields.io/badge/License-MIT-blue)](LICENSE) [Documentation](https://docs.runpod.io) • [Examples](examples) • [Discord](https://discord.gg/pJ3P2DbUUq)