Repository navigation
fix(analyze): handle non-string label and source_file safely in _is_file_node and _is_json_key_node - #5620
fix(analyze): handle non-string label and source_file safely in _is_file_node and _is_json_key_node#5620Gaurav-meena95 wants to merge 1 commit into
Conversation
…ile_node and _is_json_key_node
|
Thanks for the pull request, @Gaurav-meena95. A maintainer will review it soon. Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions. A couple of things that speed up review: make sure the test suite passes on Python 3.11 and 3.13, and that the change keeps extraction deterministic. |
There was a problem hiding this comment.
Graphify review 
2 possible issues to check · High impact
2 possible issues we couldn't confirm
- Non-text
source_filestill reaches the C# label helper unguarded in_is_file_node, so the PR's safety fix is incomplete ·graphify/analyze.py:94 - The new
_is_file_nodeand_is_json_key_nodetest only assertsFalse, so it would still pass if both checks always returnedFalse·tests/test_analyze.py:963
They don't change the score.
Code graph · 1195 functions depend on this change
- 1 function became more coupled.
god_nodes()(36 callers). - 68 of 658 test files are affected by this change.
- Gate, test list and every flagged function: in the Graphify check.
Reviewed 4811f87
Extractor accuracy (Swift #5641, Apex #5627, Python #5647, TypeScript #5604/#5614/#5612, Bash caller-var #5602), GitHub Actions run-step extraction (#5603), incremental correctness (#5634/#5638/#5636), symlink and semantic-cache fixes (#5617/#5618), export/report hardening and perf (#5643/#5644/#5645/#5646/#5619/#5620/#5621), and CLI/docs/skill/install work (#5629/#5628/#5626/#5624/#5623/#5625/#5642/#5583). AST cache schema 59 to 60; Swift/Apex/Python/Bash/GHA inputs re-extract on first build. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Landed in v0.9.124 (just released to PyPI), cherry-picked with your authorship preserved so it shows under your name in the history. Thanks @Gaurav-meena95 for safe handling of non-string labels/source files in the analyze predicates — verified green in the full suite and, where applicable, smoke-tested against the published package. 🙏 |
What does this PR do?
Guards
labelandsource_filein_is_file_node()and_is_json_key_node()(graphify/analyze.py) withisinstance(..., str)checks so non-string node attributes no longer crashgod_nodes()orreport.generate()withAttributeError.Problem
_is_file_node()calledlabel.startswith("."),label.endswith("()"), and_is_file_node_label(label, source_file)without checking thatlabelandsource_fileare strings, raisingAttributeError: 'int' object has no attribute 'startswith'on non-string labels._is_json_key_node()called.lower()and.strip().lower()onsource_fileandlabelwithoutisinstance(..., str)guards.Details
_is_file_node()if not label:/if source_file:if not isinstance(label, str) or not label:/if isinstance(source_file, str) and source_file:AttributeErroron non-stringlabelorsource_file_is_json_key_node()(attrs.get(...) or "").lower()isinstance(..., str)check before.lower()/.strip()AttributeErroron integer/non-string attributestests/test_analyze.pylabel/source_filein_is_file_node/_is_json_key_nodetest_file_and_json_key_node_checks_handle_non_string_attrs_is_file_node,_is_json_key_node, andgod_nodesbehaviourType of change
How was this tested?