Skip to content

Commit 5002ca9

Browse files
committed
fix: cluster configuration validation for bool type
As bool is a subtype of int, True/False was considered as 1/0
1 parent e666e0a commit 5002ca9

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/codeflare_sdk/common/utils/unit_test_support.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def createClusterWrongType():
5555
config = ClusterConfiguration(
5656
name="unit-test-cluster",
5757
namespace="ns",
58-
num_workers=2,
58+
num_workers=True,
5959
worker_cpu_requests=[],
6060
worker_cpu_limits=4,
6161
worker_memory_requests=5,

src/codeflare_sdk/ray/cluster/config.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,15 @@ def _memory_to_resource(self):
242242

243243
def _validate_types(self):
244244
"""Validate the types of all fields in the ClusterConfiguration dataclass."""
245+
errors = []
245246
for field_info in fields(self):
246247
value = getattr(self, field_info.name)
247248
expected_type = field_info.type
248249
if not self._is_type(value, expected_type):
249-
raise TypeError(
250-
f"'{field_info.name}' should be of type {expected_type}"
251-
)
250+
errors.append(f"'{field_info.name}' should be of type {expected_type}.")
251+
252+
if errors:
253+
raise TypeError("Type validation failed:\n" + "\n".join(errors))
252254

253255
@staticmethod
254256
def _is_type(value, expected_type):
@@ -268,6 +270,11 @@ def check_type(value, expected_type):
268270
)
269271
if origin_type is tuple:
270272
return all(check_type(elem, etype) for elem, etype in zip(value, args))
271-
return isinstance(value, expected_type)
273+
if isinstance(expected_type, type):
274+
if expected_type is int:
275+
return isinstance(value, int) and not isinstance(value, bool)
276+
if expected_type is bool:
277+
return isinstance(value, bool)
278+
return isinstance(value, expected_type)
272279

273280
return check_type(value, expected_type)

0 commit comments

Comments
 (0)