Skip to content

Commit 037cb40

Browse files
committed
datatypes: Handle missing optional lists and objects
1 parent 43f974c commit 037cb40

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

guardrails/datatypes.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,11 @@ def collect_validation(
395395
schema: Dict,
396396
) -> FieldValidation:
397397
# Validators in the main list data type are applied to the list overall.
398-
399398
validation = self._constructor_validation(key, value)
400399

400+
if value is None and self.optional:
401+
return validation
402+
401403
if len(self._children) == 0:
402404
return validation
403405

@@ -435,9 +437,11 @@ def collect_validation(
435437
schema: Dict,
436438
) -> FieldValidation:
437439
# Validators in the main object data type are applied to the object overall.
438-
439440
validation = self._constructor_validation(key, value)
440441

442+
if value is None and self.optional:
443+
return validation
444+
441445
if len(self._children) == 0:
442446
return validation
443447

0 commit comments

Comments
 (0)