Skip to content

Commit f846aaf

Browse files
committed
fix: Missing keys are misclassified as invalid fields in required string-field helpers.
1 parent f61d27f commit f846aaf

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

models/from_dict_validation.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ def require_non_empty_str(value: Any, *, model: str, field: str) -> str:
3535

3636
def require_non_empty_str_field(raw: dict[str, Any], key: str, *, model: str) -> str:
3737
"""Validate a non-empty string field read from raw."""
38-
value = raw.get(key)
38+
if key not in raw:
39+
raise SchemaError(model, key)
40+
value = raw[key]
3941
if not isinstance(value, str) or not value:
4042
raise SchemaError(
4143
model,
@@ -53,7 +55,9 @@ def require_non_empty_str_fields(
5355
) -> None:
5456
"""Validate multiple non-empty string fields in raw (ExportEntry pattern)."""
5557
for key in keys:
56-
value = raw.get(key)
58+
if key not in raw:
59+
raise SchemaError(model, key)
60+
value = raw[key]
5761
if not isinstance(value, str) or value == "":
5862
raise SchemaError(
5963
model,

0 commit comments

Comments
 (0)