Skip to content

fix(analyze): handle non-string label and source_file safely in _is_file_node and _is_json_key_node - #5620

Closed
Gaurav-meena95 wants to merge 1 commit into
Graphify-Labs:v8from
Gaurav-meena95:fix/analyze-non-str-file-node
Closed

Gaurav-meena95 wants to merge 1 commit into
Graphify-Labs:v8from
Gaurav-meena95:fix/analyze-non-str-file-node

Conversation

@Gaurav-meena95

Copy link
Copy Markdown
Contributor

What does this PR do?

Guards label and source_file in _is_file_node() and _is_json_key_node() (graphify/analyze.py) with isinstance(..., str) checks so non-string node attributes no longer crash god_nodes() or report.generate() with AttributeError.

Problem

  1. _is_file_node() called label.startswith("."), label.endswith("()"), and _is_file_node_label(label, source_file) without checking that label and source_file are strings, raising AttributeError: 'int' object has no attribute 'startswith' on non-string labels.
  2. _is_json_key_node() called .lower() and .strip().lower() on source_file and label without isinstance(..., str) guards.

Details

Target Previous Updated Rationale
_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: Prevent AttributeError on non-string label or source_file
_is_json_key_node() (attrs.get(...) or "").lower() isinstance(..., str) check before .lower() / .strip() Prevent AttributeError on integer/non-string attributes
tests/test_analyze.py No coverage for non-string label/source_file in _is_file_node / _is_json_key_node Added test_file_and_json_key_node_checks_handle_non_string_attrs Pin _is_file_node, _is_json_key_node, and god_nodes behaviour

Type of change

  • Bug fix
  • Tests or CI

How was this tested?

uv run pytest tests/test_analyze.py tests/test_god_nodes_cli.py tests/test_report.py -q
uv run ruff check graphify/analyze.py tests/test_analyze.py
PATH="$(pwd)/.venv/bin:$PATH" uv run pre-commit run --all-files
uv run graphify update .

@github-actions

Copy link
Copy Markdown

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.

@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Nov 29, 2026

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graphify review View in Graphify

Nothing blocking · 2 possible issues to check · Merge confidence 5/5

2 possible issues to check · High impact

2 possible issues we couldn't confirm
  • Non-text source_file still 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_node and _is_json_key_node test only asserts False, so it would still pass if both checks always returned False · 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

safishamsi added a commit that referenced this pull request Nov 30, 2026
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]>
@safishamsi

Copy link
Copy Markdown
Member

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. 🙏

@safishamsi safishamsi closed this Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor Pull request from a returning community contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants