Skip to content

Commit 51f22bd

Browse files
authored
Fixes issue #373 for required input validation (#379)
* fixed and added a test case for Input validation "not working as expected #373" * added an additional unit test for None
1 parent 2543f34 commit 51f22bd

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

runpod/serverless/utils/rp_validator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def _validate_input_against_schema(schema, validated_input, error_list):
7070

7171
# Check for the correct type.
7272
is_instance = isinstance(validated_input[key], rules["type"])
73-
if validated_input[key] is not None and not is_instance:
73+
if not is_instance:
7474
_add_error(
7575
error_list,
7676
f"{key} should be {rules['type']} type, not {type(validated_input[key])}.",

tests/test_serverless/test_utils/test_validate.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,24 @@ def test_validate_rules_not_dict(self):
9999
result = rp_validator.validate(self.raw_input, {"x": "not dict"})
100100
self.assertIn("errors", result)
101101

102+
def test_validate_simple_input(self):
103+
"""
104+
Tests validate with simple input
105+
"""
106+
result = rp_validator.validate(
107+
{"my_input": None}, {"my_input": {"type": str, "required": True}}
108+
)
109+
self.assertIn("errors", result)
110+
111+
def test_validate_none_type(self):
112+
"""
113+
Tests validate with None type
114+
"""
115+
result = rp_validator.validate(
116+
{"my_input": None}, {"my_input": {"type": type(None), "required": True}}
117+
)
118+
self.assertNotIn("errors", result)
119+
102120

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

0 commit comments

Comments
 (0)