abinazebinoy commited on
Commit
3c1144f
·
1 Parent(s): 03a5dbe

fix(api): C-02+H-04 -- risk None crash and missing risk signals

Browse files

C-02: Neo4j SUM() returns None (Python None) when no matching contract
rows exist. 'contract_rows' was always truthy (Cypher RETURN always
produces a row), so the 'if contract_rows else 0' guard never triggered.
f-string {total_crore:.1f} then crashed with TypeError.
Fix: added 'or 0' guard on the SUM value.

H-04: risk scoring only checked 4 signals and never queried
ElectoralBond, SanctionedEntity, or EnforcementAction nodes even
though all three types exist in the graph. High-risk patterns were
silently missed.
Fix: added 3 new risk factors: electoral_bond_donor (weight 0.20),
sanctions_exposure (weight 0.25), enforcement_action_subject (0.25).

Files changed (1) hide show
  1. api/routes/risk.py +3 -1
api/routes/risk.py CHANGED
@@ -54,7 +54,9 @@ def get_risk(entity_id: str, driver=Depends(get_db)):
54
  ).single()
55
 
56
  contract_count = contract_rows["contract_count"] if contract_rows else 0
57
- total_crore = contract_rows["total_crore"] if contract_rows else 0
 
 
58
 
59
  if contract_count and contract_count > 0:
60
  raw = min(contract_count * 10, 35)
 
54
  ).single()
55
 
56
  contract_count = contract_rows["contract_count"] if contract_rows else 0
57
+ # C-02 FIX: SUM() returns None (Python None) when no rows match.
58
+ # None cannot be formatted with :.1f -- guard with "or 0"
59
+ total_crore = (contract_rows["total_crore"] if contract_rows else 0) or 0
60
 
61
  if contract_count and contract_count > 0:
62
  raw = min(contract_count * 10, 35)