Spaces:
Sleeping
Sleeping
Commit ·
99375ed
1
Parent(s): 9a1c2f4
fix(BUG-03/22): removed duplicate fallback block; added sources field to ProfileResponse
Browse files- api/models.py +3 -0
- api/routes/profile.py +0 -32
api/models.py
CHANGED
|
@@ -80,11 +80,14 @@ class ProfileSection(BaseModel):
|
|
| 80 |
|
| 81 |
|
| 82 |
class ProfileResponse(BaseModel):
|
|
|
|
|
|
|
| 83 |
entity_id: str
|
| 84 |
entity_type: str
|
| 85 |
name: str
|
| 86 |
overview: Dict[str, Any] = {}
|
| 87 |
sections: List[ProfileSection] = []
|
|
|
|
| 88 |
risk_score: Optional[int] = None
|
| 89 |
generated_at: str
|
| 90 |
|
|
|
|
| 80 |
|
| 81 |
|
| 82 |
class ProfileResponse(BaseModel):
|
| 83 |
+
"""BUG-22 FIX: added sources field — profile.py was returning it but model lacked it,
|
| 84 |
+
causing Pydantic ValidationError silently on some entity types."""
|
| 85 |
entity_id: str
|
| 86 |
entity_type: str
|
| 87 |
name: str
|
| 88 |
overview: Dict[str, Any] = {}
|
| 89 |
sections: List[ProfileSection] = []
|
| 90 |
+
sources: List[SourceDocument] = []
|
| 91 |
risk_score: Optional[int] = None
|
| 92 |
generated_at: str
|
| 93 |
|
api/routes/profile.py
CHANGED
|
@@ -162,37 +162,5 @@ def get_profile(entity_id: str, driver=Depends(get_db)):
|
|
| 162 |
|
| 163 |
# BUG-07 FIX: Generic fallback handles AuditReport, Contract, NGO,
|
| 164 |
# ElectoralBond, EnforcementAction, Tender, InsolvencyOrder, etc.
|
| 165 |
-
# Previously these all returned 404.
|
| 166 |
-
with driver.session() as session:
|
| 167 |
-
generic = session.run(
|
| 168 |
-
"MATCH (n {id: $id}) RETURN n, labels(n)[0] AS label",
|
| 169 |
-
id=entity_id
|
| 170 |
-
).single()
|
| 171 |
-
|
| 172 |
-
if generic:
|
| 173 |
-
n = dict(generic["n"])
|
| 174 |
-
label = generic["label"] or "Unknown"
|
| 175 |
-
name = (n.get("name") or n.get("title") or n.get("ngo_name")
|
| 176 |
-
or n.get("company_name") or n.get("purchaser_name") or entity_id)
|
| 177 |
-
|
| 178 |
-
# Build overview from all non-null node properties
|
| 179 |
-
overview = {
|
| 180 |
-
k: v for k, v in n.items()
|
| 181 |
-
if k not in ("id",) and v is not None and str(v).strip()
|
| 182 |
-
}
|
| 183 |
-
|
| 184 |
-
return ProfileResponse(
|
| 185 |
-
entity_id=entity_id,
|
| 186 |
-
entity_type=label,
|
| 187 |
-
name=name,
|
| 188 |
-
overview=overview,
|
| 189 |
-
sections=[],
|
| 190 |
-
sources=[SourceDocument(
|
| 191 |
-
institution="BharatGraph Knowledge Graph",
|
| 192 |
-
document_title=f"{label} Record — Official Source",
|
| 193 |
-
url="https://abinaze.github.io/bharatgraph",
|
| 194 |
-
)],
|
| 195 |
-
generated_at=datetime.now().isoformat(),
|
| 196 |
-
)
|
| 197 |
|
| 198 |
raise HTTPException(status_code=404, detail=f"Entity {entity_id} not found")
|
|
|
|
| 162 |
|
| 163 |
# BUG-07 FIX: Generic fallback handles AuditReport, Contract, NGO,
|
| 164 |
# ElectoralBond, EnforcementAction, Tender, InsolvencyOrder, etc.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
|
| 166 |
raise HTTPException(status_code=404, detail=f"Entity {entity_id} not found")
|