abinazebinoy commited on
Commit
5d9b8a9
·
1 Parent(s): 1ffe057

fix(api+graph+pipeline): M-04+M-05+M-08+M-09 -- misc medium fixes

Browse files

M-04: /debug/env endpoint was publicly accessible with no auth gate.
It revealed NEO4J_URI prefix and credential configuration status.
Fix: added same DEBUG_MODE env-var gate as /debug/neo4j.

M-05: Wikidata enrichment used exact name match (=) -- any difference
in spacing, middle name, honorific, or transliteration caused a silent
miss. With Indian names this is extremely common.
Fix: changed to CONTAINS match in both directions for fuzzy matching.

M-08: --parallel flag had action='store_true', default=True making it
always True whether passed or not. The flag had zero effect. Confusing
for operators who expected --parallel to mean something.
Fix: removed --parallel; --sequential now inverts the default.

M-09: startNode(rel).id and endNode(rel).id in Cypher can return null
if a node has no 'id' property. This created edges with null source/target
silently corrupting graph output.
Fix: added isinstance str check to filter null src/tgt before appending.

api/main.py CHANGED
@@ -210,6 +210,10 @@ async def websocket_feed(websocket: WebSocket):
210
 
211
  @app.get("/debug/env")
212
  def debug_env():
 
 
 
 
213
  return {
214
  "neo4j_uri_set": bool(os.getenv("NEO4J_URI")),
215
  "neo4j_user_set": bool(os.getenv("NEO4J_USER")),
 
210
 
211
  @app.get("/debug/env")
212
  def debug_env():
213
+ # M-04 FIX: gate behind DEBUG_MODE same as /debug/neo4j
214
+ if os.getenv("DEBUG_MODE", "").lower() not in ("1", "true", "yes"):
215
+ from fastapi import HTTPException as _HE
216
+ raise _HE(status_code=404, detail="Not found")
217
  return {
218
  "neo4j_uri_set": bool(os.getenv("NEO4J_URI")),
219
  "neo4j_user_set": bool(os.getenv("NEO4J_USER")),
api/routes/graph.py CHANGED
@@ -84,8 +84,10 @@ def get_connections(
84
  src = rel_step.get("src", "")
85
  tgt = rel_step.get("tgt", "")
86
  rtype = rel_step.get("type", "RELATED_TO")
87
- if src and tgt:
88
- # BUG-10 FIX: skip duplicate edges -- depth>1 paths share edges
 
 
89
  edge_key = (src, tgt, rtype)
90
  if edge_key not in _edge_seen:
91
  _edge_seen.add(edge_key)
 
84
  src = rel_step.get("src", "")
85
  tgt = rel_step.get("tgt", "")
86
  rtype = rel_step.get("type", "RELATED_TO")
87
+ # M-09 FIX: startNode/endNode may return null .id if node
88
+ # was created without an id property -- filter those out
89
+ if src and tgt and isinstance(src, str) and isinstance(tgt, str):
90
+ # skip duplicate edges -- depth>1 paths share edges
91
  edge_key = (src, tgt, rtype)
92
  if edge_key not in _edge_seen:
93
  _edge_seen.add(edge_key)
graph/loader.py CHANGED
@@ -912,7 +912,7 @@ class GraphLoader:
912
  try:
913
  result = self._run("""
914
  MATCH (p:Politician)
915
- WHERE toLower(p.name) = toLower($name)
916
  OR any(a IN coalesce(p.aliases,[]) WHERE toLower(a) = toLower($name))
917
  SET p.wikidata_id = coalesce($wikidata_id, p.wikidata_id),
918
  p.birth_year = coalesce($birth_year, p.birth_year),
 
912
  try:
913
  result = self._run("""
914
  MATCH (p:Politician)
915
+ WHERE toLower(p.name) CONTAINS toLower($name) OR toLower($name) CONTAINS toLower(p.name)
916
  OR any(a IN coalesce(p.aliases,[]) WHERE toLower(a) = toLower($name))
917
  SET p.wikidata_id = coalesce($wikidata_id, p.wikidata_id),
918
  p.birth_year = coalesce($birth_year, p.birth_year),
processing/pipeline.py CHANGED
@@ -420,8 +420,10 @@ class BharatGraphPipeline:
420
  if __name__ == "__main__":
421
  parser = argparse.ArgumentParser(description="BharatGraph Full Pipeline (20 scrapers)")
422
  parser.add_argument("--scrapers", type=str, default=None)
423
- parser.add_argument("--parallel", action="store_true", default=True)
424
- parser.add_argument("--sequential", action="store_true", default=False)
 
 
425
  args = parser.parse_args()
426
  scrapers = args.scrapers.split(",") if args.scrapers else None
427
  parallel = not args.sequential
 
420
  if __name__ == "__main__":
421
  parser = argparse.ArgumentParser(description="BharatGraph Full Pipeline (20 scrapers)")
422
  parser.add_argument("--scrapers", type=str, default=None)
423
+ # M-08 FIX: --parallel was action=store_true,default=True making it always True
424
+ # --sequential now sets parallel=False, and --parallel is removed
425
+ parser.add_argument("--sequential", action="store_true", default=False,
426
+ help="Run scrapers sequentially (default: parallel)")
427
  args = parser.parse_args()
428
  scrapers = args.scrapers.split(",") if args.scrapers else None
429
  parallel = not args.sequential