You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Python: codegraph_callers misses module-attribute call sites (module.func(...) after from pkg import module) — zero recall on a common test/namespacing pattern #578
Python: codegraph_callers misses module-attribute call sites (module.func(...) after from pkg import module) — zero recall on a common test/namespacing pattern
Summary
On Python, a call made through a module object attribute — module.func(...) where module was bound via import pkg.module as module or from pkg import module — produces no calls edge, so codegraph_callers / callees / impact / trace return empty for the target. Both the caller node and the callee node are correctly indexed; only the edge between them is dropped.
This is the same root cause class confirmed and fixed for Go in #388 / #469 (isExternalImport → resolveViaImport returning null → fall-through), and analogous to the per-language import-resolution fixes already shipped for Java/Kotlin (#314), TypeScript (#359), and C# (#381). Python was never covered. This was flagged in a comment on #388, but since that issue was scoped and closed as Go-specific, it has no dedicated tracking — hence this issue.
tests/test_mod.py — both common module-attribute forms:
frompkgimportmod# form 1: from-import of the moduleimportpkg.modasmod2# form 2: aliased module importdeftest_helper():
assertmod.helper(1) ==1# attribute access on module objectassertmod2.helper(2) ==2
Expected:codegraph_callers helper → 2 callers (the two *.helper(...) calls in test_mod.py). Observed:No callers found.
Compare with the form that does work today:
frompkg.modimporthelper# bare-name importdeftest_helper():
asserthelper(1) ==1# bare call → edge IS created
So the gap is specifically the qualified/attribute call shape, exactly mirroring Go's pkg.Func(...).
Production evidence (this is not a toy-only failure)
In the RAGFlow codebase, dialog_service._repair_grounded_citation_alignment is called by 9 regression tests via module-attribute access:
codegraph_callers _repair_grounded_citation_alignment → "No callers found"
Same result for _preserve_grounded_reference_labels. Both ends exist; the edge does not.
Real-world impact:codegraph_callers reporting zero callers led to a (correctly caught, but only via textual grep) near-miss where these functions looked like dead code. For any user relying on callers/impact to make "is this safe to delete?" decisions, this is a silent high-recall miss. The pattern (from pkg import module then module.helper(...)) is extremely common in Python test suites that use module-attribute access for namespacing and ergonomic monkeypatching.
Hypothesis
Parallel to the #469 Go root cause: the Python resolver likely resolves a call's qualifier (module) to the imported module, but the qualified-member lookup (module.helper → the helper def node) either isn't attempted for the module.attr(...) call shape or fails to match because the target's stored name is the bare helper and the resolver doesn't strip/relate the module qualifier. Edge is then silently dropped (no fall-through to a bad match, just nothing — consistent with the clean ~0 recall).
Ask
Can the Python import/call resolver get the same treatment Go received in fix(resolution): Go cross-package qualified calls resolve via go.mod (#388) #469 — resolve module.func(...) attribute calls (where module is a from pkg import module / import pkg.module as module binding) to the exported member node and emit the calls edge?
Both from pkg import module and import pkg.module as module qualifier forms should be covered, plus re-exported aggregator modules.
Happy to run targeted queries against the local .codegraph/codegraph.db (e.g. dump edges filtered to the test file) to validate any fix or hypothesis.
Python:
codegraph_callersmisses module-attribute call sites (module.func(...)afterfrom pkg import module) — zero recall on a common test/namespacing patternSummary
On Python, a call made through a module object attribute —
module.func(...)wheremodulewas bound viaimport pkg.module as moduleorfrom pkg import module— produces nocallsedge, socodegraph_callers/callees/impact/tracereturn empty for the target. Both the caller node and the callee node are correctly indexed; only the edge between them is dropped.This is the same root cause class confirmed and fixed for Go in #388 / #469 (
isExternalImport→resolveViaImportreturningnull→ fall-through), and analogous to the per-language import-resolution fixes already shipped for Java/Kotlin (#314), TypeScript (#359), and C# (#381). Python was never covered. This was flagged in a comment on #388, but since that issue was scoped and closed as Go-specific, it has no dedicated tracking — hence this issue.Environment
@colbymchenry/codegraph@0.9.7(the release containing the Go fix fix(resolution): Go cross-package qualified calls resolve via go.mod (#388) #469f1b79ee, Java feat: Add Java import resolution to extractImportMappings for cross-module disambiguation #314, TS TypeScripttypealias members not used in method-call resolution → false cross-modulecallsedges via path-proximity #359, C# C# extractor produces zeroreferencesedges — type annotations on parameters, return types, and fields are never extracted #381)codegraph initre-run immediately before querying — not a stale 0.9.4 index)Minimal reproduction
pkg/mod.py:tests/test_mod.py— both common module-attribute forms:Expected:
codegraph_callers helper→ 2 callers (the two*.helper(...)calls intest_mod.py).Observed:
No callers found.Compare with the form that does work today:
So the gap is specifically the qualified/attribute call shape, exactly mirroring Go's
pkg.Func(...).Production evidence (this is not a toy-only failure)
In the RAGFlow codebase,
dialog_service._repair_grounded_citation_alignmentis called by 9 regression tests via module-attribute access:Graph state on the fresh 0.9.7 index:
_repair_grounded_citation_alignment(callee)codegraph_search→dialog_service.py:754test_repair_grounded_citation_alignment_*(callers)codegraph_search→test_dialog_service_prompt_sanitization.py:1757/1777/1796/1815callsedge between themcodegraph_callers _repair_grounded_citation_alignment→ "No callers found"Same result for
_preserve_grounded_reference_labels. Both ends exist; the edge does not.Real-world impact:
codegraph_callersreporting zero callers led to a (correctly caught, but only via textual grep) near-miss where these functions looked like dead code. For any user relying oncallers/impactto make "is this safe to delete?" decisions, this is a silent high-recall miss. The pattern (from pkg import modulethenmodule.helper(...)) is extremely common in Python test suites that use module-attribute access for namespacing and ergonomic monkeypatching.Hypothesis
Parallel to the #469 Go root cause: the Python resolver likely resolves a call's qualifier (
module) to the imported module, but the qualified-member lookup (module.helper→ thehelperdef node) either isn't attempted for themodule.attr(...)call shape or fails to match because the target's stored name is the barehelperand the resolver doesn't strip/relate the module qualifier. Edge is then silently dropped (no fall-through to a bad match, just nothing — consistent with the clean ~0 recall).Ask
module.func(...)attribute calls (wheremoduleis afrom pkg import module/import pkg.module as modulebinding) to the exported member node and emit thecallsedge?from pkg import moduleandimport pkg.module as modulequalifier forms should be covered, plus re-exported aggregator modules..codegraph/codegraph.db(e.g. dumpedgesfiltered to the test file) to validate any fix or hypothesis.Related
codegraph_callersseverely under-reports cross-package qualified calls (pkg.Func(...)) — <1% recall on a large Go monorepo #388 — Go: same symptom, fixed Go-only in fix(resolution): Go cross-package qualified calls resolve via go.mod (#388) #469 (f1b79ee). This Python case was noted in a comment there but the issue was closed as Go-specific.typealias members not used in method-call resolution → false cross-modulecallsedges via path-proximity #359 — TypeScript false/missing edges (fixed)referencesedges — type annotations on parameters, return types, and fields are never extracted #381 — C# missing reference edges (fixed)