Skip to content

Commit eff7404

Browse files
committed
datatypes: Handle missing optional lists and objects
1 parent 82b4a2e commit eff7404

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
@@ -399,9 +399,11 @@ def collect_validation(
399399
schema: Dict,
400400
) -> FieldValidation:
401401
# Validators in the main list data type are applied to the list overall.
402-
403402
validation = self._constructor_validation(key, value)
404403

404+
if value is None and self.optional:
405+
return validation
406+
405407
if len(self._children) == 0:
406408
return validation
407409

@@ -439,9 +441,11 @@ def collect_validation(
439441
schema: Dict,
440442
) -> FieldValidation:
441443
# Validators in the main object data type are applied to the object overall.
442-
443444
validation = self._constructor_validation(key, value)
444445

446+
if value is None and self.optional:
447+
return validation
448+
445449
if len(self._children) == 0:
446450
return validation
447451

0 commit comments

Comments
 (0)