Skip to content

Commit 2720864

Browse files
committed
fix(spp_scoring): strict mode validates false/invalid values for required indicators
Previously only checked for None. Now also catches False, empty string, and other falsy values (except 0 and True) when the indicator is required. Error message includes the actual value for debugging.
1 parent 12f50d4 commit 2720864

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

spp_scoring/models/scoring_engine.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,16 @@ def _calculate_indicator(self, indicator, registrant):
206206

207207
result["field_value"] = field_value
208208

209-
# Handle missing values
210-
if field_value is None:
209+
# Handle missing or falsy values
210+
# For required indicators, treat False/None/empty as missing
211+
if field_value is None or (
212+
indicator.is_required and field_value is not True and not field_value and field_value != 0
213+
):
211214
if indicator.is_required:
212-
result["error"] = _("Required field '%s' is missing.") % indicator.field_path
215+
result["error"] = _("Required field '%(path)s' has no valid value (got: %(value)s).") % {
216+
"path": indicator.field_path,
217+
"value": repr(field_value),
218+
}
213219
return result
214220
field_value = indicator._convert_default_value()
215221

0 commit comments

Comments
 (0)