Skip to content

Python: aliased from-import across a non-repo-root source root loses the CALLS edge #1390

Description

@dergachoff

Problem

When the Python source root is not the repo root (setuptools src/ layout, monorepo service dirs), an aliased from-import produces no CALLS edge: trace_path(direction="inbound") returns callers_total: 0 for a function with real callers. The same files with a plain import resolve fine. Found live on v0.9.1-rc.1: two agent sessions concluded a production function had zero callers.

Evidence

Each case freshly indexed on v0.9.1-rc.1:

structure import inbound trace
flat, same dir aliased caller found
repo-root package (services/) aliased caller found
source root under api/ (import says services.callee, QN says api.services.callee) plain caller found
same layout, same files aliased 0 callers

Minimal repro, two files under <repo>/api/services/:

# callee.py
def target_fn(x):
    return x + 1

# caller.py
from services.callee import target_fn as _target_fn

def wrapper(x):
    return _target_fn(x)

index_repository then trace_path(function_name="target_fn", direction="inbound") → callers_total: 0; the plain-import twin repo indexes one more edge (35 vs 34) and finds wrapper. search_graph still shows in-degree 1 (the import edge), so CALLS resolution specifically is the gap.

A plain call resolves by call-site name == target name; the alias forces import-path resolution, which assumes the repo root — services.callee never maps onto api.services.callee. Distinct from #875 (aliased import with repo-root paths, fixed by #979) and #1237 (plain bare import; plain passes here).

Expected fix

Make import-path resolution tolerate non-repo-root source roots (e.g. suffix-match the import path against registered module QNs), with the aliased src-layout case as a regression test.

Activity

  1. vinitgirdhar commented on Aug 1, 2026

    @vinitgirdhar

    Hello, I can fix this issue. Can you please assign this issue to me?

  2. added this to the 0.9.1-rc milestone on Aug 3, 2026
  3. added
    priority/highNeeds near-term maintainer attention; high-impact bug, regression, safety issue, or release blocker.
    on Aug 3, 2026
  4. DeusData commented on Aug 3, 2026

    @DeusData
    Owner

    Thank you for volunteering to help. PR #1371 is already the active implementation for this issue, so I do not want to assign overlapping work to a second contributor and have both of you spend time on the same fix. I will leave the issue unassigned while that PR is active.

    The most useful help would be an independent test of #1371 on a small public Python fixture once the remaining IMPORTS graph-shape decision is resolved. That would add evidence without duplicating the implementation. Thank you for offering.

  5. dergachoff commented on Sep 19, 2026

    @dergachoff
    ContributorAuthor

    Confirmed fixed on v0.11.0. Reran the repro — the aliased from services.callee import target_fn as _target_fn across the api/ source root now traces back to its caller (callers_total: 1, was 0), same as the plain import. Looks like #1371 did it, so this can close.

  6. DeusData commented on Sep 25, 2026

    @DeusData
    Owner

    Thank you, @dergachoff, for the clear src-layout repro and for coming back to confirm on v0.11.0. Much appreciated! You're right: #1371 (merged as 07cac7d6, first released in v0.10.7) resolves the aliased import across a non-repo-root source root, and your case is its regression test. Thanks also to @Joseph-MingEn for the fix. Closing as fixed.

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

    bugSomething isn't workingparsing/qualityGraph extraction bugs, false positives, missing edgespriority/highNeeds near-term maintainer attention; high-impact bug, regression, safety issue, or release blocker.

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions