Skip to content

Commit

Permalink
Fixes issue #373 for required input validation (#379)
Browse files Browse the repository at this point in the history
* fixed and added a test case for  Input validation "not working as expected #373"
* added an additional unit test for None
  • Loading branch information
gabewillen authored Dec 5, 2024
1 parent 2543f34 commit 51f22bd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion runpod/serverless/utils/rp_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def _validate_input_against_schema(schema, validated_input, error_list):

# Check for the correct type.
is_instance = isinstance(validated_input[key], rules["type"])
if validated_input[key] is not None and not is_instance:
if not is_instance:
_add_error(
error_list,
f"{key} should be {rules['type']} type, not {type(validated_input[key])}.",
Expand Down
18 changes: 18 additions & 0 deletions tests/test_serverless/test_utils/test_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,24 @@ def test_validate_rules_not_dict(self):
result = rp_validator.validate(self.raw_input, {"x": "not dict"})
self.assertIn("errors", result)

def test_validate_simple_input(self):
"""
Tests validate with simple input
"""
result = rp_validator.validate(
{"my_input": None}, {"my_input": {"type": str, "required": True}}
)
self.assertIn("errors", result)

def test_validate_none_type(self):
"""
Tests validate with None type
"""
result = rp_validator.validate(
{"my_input": None}, {"my_input": {"type": type(None), "required": True}}
)
self.assertNotIn("errors", result)


if __name__ == "__main__":
unittest.main()

0 comments on commit 51f22bd

Please sign in to comment.