Repository navigation
fix(analyze): handle non-string label and source_file safely in _is_file_node and _is_json_key_node - #5620
Open
Gaurav-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
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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?