graphify icon indicating copy to clipboard operation
graphify copied to clipboard

Suppress sourceless external call targets like FastAPI HTTPException from bridge analysis

Open SameTrouble opened this issue 3 months ago • 2 comments

Problem

When graphifying a FastAPI-heavy Python package, HTTPException becomes a high-degree cross-community bridge / god node even though it is an external framework exception constructor, not a project architecture abstraction.

Observed on graphifyy==0.9.50 while graphifying packages/bsquant_server in a Python monorepo:

  • Graph size: 3,634 nodes / 10,820 graph edges / 143 communities.
  • Node: httpexception
    • label: HTTPException
    • source_file: empty string
    • origin: ast
    • degree: 124
    • relations: calls: 124
    • confidence: EXTRACTED: 9, INFERRED: 115
  • The node appeared as a top bridge / god-node-like result, crossing router communities such as Catalog Router, Workflows Router, Datasets Router, Factors Router, Components Router, and Shared API.

The affected source patterns are ordinary FastAPI error responses, e.g.:

from fastapi import Cookie, Header, HTTPException

raise HTTPException(status_code=401, detail="missing credentials")
raise HTTPException(status_code=403, detail="permission denied")

and router exception translation such as:

except CatalogAuthorizationError as exc:
    raise HTTPException(status_code=403, detail=str(exc)) from exc

These edges make HTTPException look like a core cross-module dependency, but it is really framework error-response construction noise.

Why it seems to happen

From a quick read of the installed extractor:

  • The cross-file call resolver walks all_raw_calls and skips known language builtins, member calls, bash calls, etc.
  • It then resolves by global label candidate.
  • For sourceless external nodes, _lang_family(nid_to_source_file.get(candidate)) is None, so the cross-language guard keeps the candidate.
  • If there is a unique candidate but no import evidence, the resolver still emits calls with confidence="INFERRED" and confidence_score=0.85.

Relevant installed-package locations in graphifyy==0.9.50:

  • graphify/extract.py: cross-file raw-call loop around the callee in _LANGUAGE_BUILTIN_GLOBALS guard and candidate filtering.
  • graphify/extract.py: direct call emission path that emits calls / INFERRED / 0.85 when has_import_evidence is false.

Expected behavior

External framework constructors / exceptions such as FastAPI HTTPException should not become central architecture bridge nodes by default.

Possible fixes:

  1. Suppress cross-file direct calls edges to sourceless external call targets unless the target is a project-defined callable or has explicit import evidence tied to a local module.
  2. Namespace sourceless external targets as external dependencies and exclude/downweight them from god node, bridge, and surprising-connection analysis.
  3. Add common external/framework exception constructors to a noise set, e.g. HTTPException, while keeping project-defined exception classes intact.
  4. Model this as raises / error_response metadata rather than a project-internal calls edge.

Reproduction sketch

A minimal FastAPI module likely reproduces it:

from fastapi import APIRouter, HTTPException

router = APIRouter()

@router.get("/x")
def get_x():
    raise HTTPException(status_code=404, detail="not found")

Run:

graphify .

Then inspect graphify-out/graph.json for the httpexception node and its incoming calls edges.

Acceptance criteria

  • HTTPException and similar sourceless external framework constructors no longer appear as high-degree project bridge / god nodes.
  • Calls to project-local exception classes still remain represented where useful.
  • If external calls are retained, they are typed or downweighted so report sections do not present them as core architecture abstractions.
  • Add a regression test for a small FastAPI file that raises HTTPException(...) from multiple handlers.

SameTrouble avatar Aug 28 '26 06:08 SameTrouble

I was able to reproduce this on graphify version0.9.50.
A sourceless httpexception node is created. The type-annotation example creates an extracted call, while the bare raise, catch/re-raise, and except HTTPException examples create INFERRED calls to the same node. so the original single-file example didn’t reproduce it, but these combined cases do.

d_type_annotation_make_error -> httpexception | calls | EXTRACTED a_bare_raise_get_catalog -> httpexception | calls | INFERRED b_except_reraise_get_workflows -> httpexception | calls | INFERRED c_except_httpexception_get_datasets -> httpexception | calls | INFERRED

cyber1830 avatar Aug 29 '26 10:08 cyber1830

Fixed in v0.9.62 (on PyPI) via #3531, thanks @DevChiniwala. Thanks for the report!

safishamsi avatar Sep 15 '26 18:09 safishamsi