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
{{ message }}
Repository navigation
[Bug]: Python: from-importing a function that has a nested def makes every module.func() call from that file lose its calls edge (0.9.58+) #3887
Since 0.9.58, if a file does from pkg import mod and also from pkg.mod import f, where f is a function
that contains a nested def, everymod.<anything>() call in that file loses its calls edge. 0.9.57
resolves them. Still reproduces on 0.9.70 and on v8@4c21b15e9b.
Root cause (found by instrumenting the resolver; the intermediate edge does not survive to graph.json):
since #3410 an outer function with a nested def is the source of a contains edge. The module arm of _resolve_python_member_calls treats any imports target that has contains children as a candidate module:
mods= [tfortinimported_by_filenode.get(caller_file, ())
iftincontains_childrenand (_module_stem_key(t) ==rkeyorfile_aliases.get(t) ==rkey)]
iflen(mods) !=1: # not an imported module, or ambiguous -> bailcontinue
The imports views -> sort_todos edge makes sort_todos a candidate, and _module_stem_key takes the stem
of its file (store), which matches the receiver. So mods == [store.py, sort_todos], and the resolver
bails as ambiguous.
calls edges from app/api/views.py
0.9.57: board() -> sort_todos(); get_archived_panel() -> parse_todo_file()
0.9.58, 0.9.62, 0.9.66, 0.9.70: board() -> sort_todos() <- parse_todo_file() lost
controls: without the nested `def key` in sort_todos -> both edges on every version
Suggested fix (one line, verified): a node that is itself contained by another node is not a module:
mods = [t for t in imported_by_filenode.get(caller_file, ())
if t in contains_children
+ and t not in file_of_node
and (_module_stem_key(t) == rkey or file_aliases.get(t) == rkey)]
On a 485-file Python subtree of our repo this line alone restores exactly the 8 lost mod.func() edges
and adds or removes nothing else (full graph diff, 0.9.70 vs 0.9.70 + this line: +8 calls, −0). On the
whole ~2,470-file repo, combined with the fix from the companion issue, the 8 are recovered and no edge is
removed.
Additional context: related but different: #2447 (other causes in the same arm), #2428 / PR #2429 (alias
stem; the un-aliased repro above is not covered by #2429), #3272 (package-form import outside the package tree).
In graphify/extract.py within _resolve_python_member_calls:
mods= [tfortinimported_by_filenode.get(caller_file, ())
iftincontains_childrenand (_module_stem_key(t) ==rkeyorfile_aliases.get(t) ==rkey)]
iflen(mods) !=1: # not an imported module, or ambiguous -> bailcontinue
When sort_todos defines an inner def key(t):, PR #3410 added a contains edge from sort_todos to key. As a result:
sort_todos in contains_children evaluates to True.
_module_stem_key(sort_todos) evaluates to Path(node["source_file"]).stem, which is "store".
mods contains both the module node (services/store.py) and the function node (sort_todos).
Because len(mods) == 2 != 1, the ambiguity guard triggers and skips resolving any store.<func>() call from that file.
Minimal Fix
Since symbol nodes (functions, classes, nested functions) are always the target of a contains edge, they are recorded in the existing file_of_node map (file_of_node[tgt] = src), while module/file nodes are never the target of contains.
Adding and t not in file_of_node to the candidate filter ensures only top-level module nodes match:
--- a/graphify/extract.py+++ b/graphify/extract.py@@ -3972,6 +3972,7 @@ def _resolve_python_member_calls(
file_aliases = import_alias_by_filenode.get(caller_file, {})
mods = [t for t in imported_by_filenode.get(caller_file, ())
if t in contains_children
+ and t not in file_of_node
and (_module_stem_key(t) == rkey or file_aliases.get(t) == rkey)]
if len(mods) != 1: # not an imported module, or ambiguous -> bail
continue
I have a branch with this 1-line fix and a regression test ready. Opening a PR shortly.
Activity
github-actions commentedon Sep 28, 2026
Thanks for opening this issue, @wpoPR. A maintainer will take a look soon.
If you would like to discuss it in real time, come say hi on our Discord server. For longer-form questions and ideas there is also GitHub Discussions.
To help us triage, please make sure the report includes what you expected, what actually happened, and the steps (and a small sample) to reproduce it.
harshaygadekar commentedon Sep 28, 2026
Confirmed and reproduced.
Root Cause
In
graphify/extract.pywithin_resolve_python_member_calls:When
sort_todosdefines an innerdef key(t):, PR #3410 added acontainsedge fromsort_todostokey. As a result:sort_todos in contains_childrenevaluates toTrue._module_stem_key(sort_todos)evaluates toPath(node["source_file"]).stem, which is"store".modscontains both the module node (services/store.py) and the function node (sort_todos).len(mods) == 2 != 1, the ambiguity guard triggers and skips resolving anystore.<func>()call from that file.Minimal Fix
Since symbol nodes (functions, classes, nested functions) are always the target of a
containsedge, they are recorded in the existingfile_of_nodemap (file_of_node[tgt] = src), while module/file nodes are never the target ofcontains.Adding
and t not in file_of_nodeto the candidate filter ensures only top-level module nodes match:I have a branch with this 1-line fix and a regression test ready. Opening a PR shortly.
fix(extract): ignore contained symbols when resolving imported modules (
safishamsi commentedon Sep 29, 2026
Fixed in v0.9.72 (now on PyPI) by #3898 — thanks @harshaygadekar.
Release: https://github.com/Graphify-Labs/graphify/releases/tag/v0.9.72