Skip to content

Relative import of a subpackage emits an abs-path slug imports_from target to a non-existent <pkg>.py #2455

Open

Description

@vanjos

A relative import of a sibling subpackage emits an imports_from edge whose target is an absolute-path-derived slug for a non-existent <subpackage>.py, instead of resolving to the subpackage's __init__.py.

Repro (minimal, deterministic on 0.9.32)

proj/pyproject.toml
proj/src/mypkg/__init__.py                 (empty)
proj/src/mypkg/api/__init__.py             (empty)
proj/src/mypkg/api/routes/__init__.py      (empty)
proj/src/mypkg/graphs/__init__.py          -> def build_graph(): return {}
proj/src/mypkg/api/routes/health.py        -> from ...graphs import build_graph

graphify update proj --no-cluster produces two edges out of health:

src_mypkg_api_routes_health --imports_from--> <abs-scan-slug>_proj_src_mypkg_graphs_py   # BUG: graphs.py does not exist
src_mypkg_api_routes_health --imports-->      src_mypkg_graphs_init_build_graph           # correct

graphs/ is a package (graphs/__init__.py), so the imports_from target should be graphs/__init__.py, which is exactly what the companion imports edge already resolves to. Instead it is a slug for a graphs.py that is not on disk.

Why it matters

The endpoint is derived from the absolute scan path, so it is machine-specific and differs per checkout path. Committed graphs then show a spurious diff on every rebuild from a different location, the same reproducibility problem as #2262 and #2273. In a real repo this fails a fail-closed host-path check.

Notes

  • Specific to the relative form. An absolute import of the same subpackage (from mypkg import graphs) resolves correctly to the package __init__, no slug.
  • Seen on a real Python src-layout package where several from ...graphs import X / from ...services import X lines each produced one of these.

Suggested fix

Resolve a relative subpackage import to the subpackage's __init__.py (match what the imports edge does), or canonicalize/drop the node-less endpoint rather than leaving the absolute-derived slug.

Activity

  1. vanjos commented on Aug 10, 2026

    @vanjos
    Author

    Confirmed this still reproduces on 0.9.36 (the minimal repro above is unchanged). Any read on whether it's a quick fix? Happy to test a patch or add detail if useful.

  2. vanjos commented on Aug 11, 2026

    @vanjos
    Author

    Still reproduces on graphify 0.9.38. The minimal repro from the report (a relative import of a subpackage, from ...graphs import build_graph where graphs/ is a package) still emits the absolute-path slug imports_from target:

    src_mypkg_api_routes_health  imports_from  <abs-scan-slug>_proj_src_mypkg_graphs_py   (non-existent graphs.py)
    src_mypkg_api_routes_health  imports       src_mypkg_graphs_init_build_graph          (correct)
    

    The imports edge resolves correctly to graphs/__init__; only the imports_from edge still points at a non-existent graphs.py via a machine-specific absolute-path slug. No change from 0.9.32.

  3. omsenjalia commented on Oct 18, 2026

    @omsenjalia
    Contributor

    This looks fixed on the v8 branch by 1c120063 (fix: resolve Python imports within scan root). Could a maintainer confirm and close?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions