Skip to content

fix(export): handle null and non-numeric edge weights in to_canvas - #5643

Closed
Gaurav-meena95 wants to merge 1 commit into
Graphify-Labs:v8from
Gaurav-meena95:fix/export-canvas-null-weight
Closed

Gaurav-meena95 wants to merge 1 commit into
Graphify-Labs:v8from
Gaurav-meena95:fix/export-canvas-null-weight

Conversation

@Gaurav-meena95

Copy link
Copy Markdown
Contributor

What does this PR do?

Guards edge weight, relation, and confidence lookups in to_canvas() (graphify/export.py) via _valid_canvas_weight() so None, bool, non-finite floats (nan/inf), oversized ints (OverflowError), or malformed strings fall back cleanly instead of crashing to_canvas().

Problem

When an edge carries "weight": null (or a non-numeric/non-finite weight), edata.get("weight", 1.0) returns None and all_edges_weighted.sort(key=lambda x: -x[0]) raises TypeError: bad operand type for unary -: 'NoneType'. Similarly, relation=None or confidence=None rendered "None [EXTRACTED]" / "[None]".

Details

Target Previous Updated Rationale
_valid_canvas_weight() (graphify/export.py) None Coerces valid numeric weights via float(), rejects None/bool/non-finite/overflowing values to 1.0 Centralize finite float validation for canvas edge sorting
to_canvas() (graphify/export.py) edata.get("weight", 1.0) and raw relation/confidence Use _valid_canvas_weight(...) and fall back on None relation/confidence Prevent TypeError/ValueError/OverflowError and malformed edge labels
tests/test_export.py No coverage for null/non-numeric canvas edge weights Added test_to_canvas_handles_null_and_non_numeric_weights Pin None, "bad", bool, nan, 10**400, and numeric string sorting

Type of change

  • Bug fix
  • Tests or CI

How was this tested?

uv run pytest tests/test_export.py tests/test_export_control_characters.py tests/test_export_path_length.py -q
uv run ruff check graphify/export.py tests/test_export.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 30, 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

Canvas export now converts invalid or non-finite edge weights to 1.0 before sorting.

2 possible issues we couldn't confirm
  • An edge whose weight is False is ranked as weight 1.0 instead of 0.0 in the canvas edge cap · graphify/export.py:1252
  • Edges with a missing confidence value are labelled EXTRACTED on the canvas, which asserts a source that is not known · graphify/export.py:1423

They don't change the score.

What this review covered
  • Some lookups asked for files or lines that do not exist; the review was told and carried on.
  • 2 of 2 changed files inspected. This is scope, not a correctness guarantee.
Code graph · 1163 functions depend on this change
  • 1 function became more coupled. to_canvas() (23 callers).
  • 54 of 658 test files are affected by this change.
  • Gate, test list and every flagged function: in the Graphify check.

Reviewed f02e94f

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 handling null and non-numeric edge weights in to_canvas — 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