Skip to content

Keep a graph's meaning intact across dump and load (Python, JS, TS) - #1

Merged
maheshvaikri-code merged 2 commits into
mainfrom
fix/identity-contract-1.4.1
Nov 5, 2026
Merged

maheshvaikri-code merged 2 commits into
mainfrom
fix/identity-contract-1.4.1

Conversation

@maheshvaikri-code

Copy link
Copy Markdown
Contributor

Summary

Four ways the same graph came back different after dump → load, found while auditing Core as the identity base for ISONGraphExt. Each is fixed in Python, TypeScript and JavaScript with the same tests in all three. A directed graph's serialized bytes are unchanged, so the cross-port golden still holds.

Defect in 1.4.0 Fix
A negative integer id did not survive reload: :p:-1 was resolved with str.isdigit(), which has no sign, so the reference became the string "-1" and every edge to it raised NodeNotFoundError — in ISONGraph, MultiGraph and the query() pattern parser References and patterns read -?[0-9]+ as an integer and resolve against the loaded node table first, so a string id "-1" is still found as a string
An undirected simple graph wrote no meta.graph, so directed=False was lost, its mirror rows came back as two independent edges, and {A->B, B->A} directed was byte-identical to {A-B} undirected Undirected graphs write meta.graph with directed false (as MultiGraph already did); the loader reads it and skips the mirror it has already reconstructed. Directed graphs write nothing new
1.5, True and None were accepted as node ids, written as 1.5 / true / null, and then no edge to them resolved Refused at add_node with InvalidIdentifierError. In JS/TS 1.0 is the integer 1 and stays accepted
float('nan') / inf were written bare and read back as the strings "nan" / "inf" New InvalidPropertyValueError (a GraphError) on add_node, add_edge, update_node and the ProtectedGraph updaters. update_node now also validates property names

Verification

  • Python: 453 → 498 passed
  • TypeScript: 183 → 221 passed, tsc --noEmit clean
  • JavaScript: 183 → 221 passed
  • .github/scripts/check_cross_port_goldens.py: all six ports agree
  • ruff check: finding count identical to main
  • Python, TS and JS emit byte-identical ISON and ISONL for an undirected graph with a negative id, a float property and an edge property

Not in this PR

Rust, C# and C++ store every node id as a string, so the negative-id and id-type changes have no equivalent there yet, and they do not emit meta.graph for an undirected graph. An undirected graph written by Python/JS/TS and read by those ports loads as directed, exactly as before. Recorded in CHANGELOG.md as the next parity item.

No version bump: the changelog entry sits under [Unreleased]. Per CONTRIBUTING.md the bump, dated changelog, tag and publish dispatches follow the merge.

🤖 Generated with Claude Code

maheshvaikri-code and others added 2 commits September 5, 2026 14:10
…kage

`from ison_graph import query` (or schema, multigraph, structural) raised
RecursionError. The lazy __getattr__ resolved each name with
`from . import <name>`, and that form probes the package with hasattr first,
which calls __getattr__ again for the same name until the stack runs out.
importlib.import_module goes to the import machinery directly; caching the
result in globals() means the hook runs once per submodule.

Present since 1.0.0. Nothing caught it because every example in the docs
writes `from ison_graph.schema import ...`, which resolves the submodule
through the import system and never reaches __getattr__.

The suite could not have caught it either: with a non-editable ison-graph in
site-packages, pytest imported that copy rather than src/, so the tests were
not running against the working tree at all. pythonpath = ["src"] pins them
to it. CI was unaffected — it installs editable.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Four ways the same graph came back different, found while auditing Core
as the identity base for ISONGraphExt:

- A negative integer id did not survive reload. References were resolved
  with str.isdigit(), which has no sign, so :p:-1 became the string "-1"
  and every edge to it raised NodeNotFoundError - in ISONGraph, MultiGraph
  and the query() pattern parser. References and patterns now read
  -?[0-9]+ as an integer and resolve against the loaded node table first.

- An undirected graph reloaded as directed. The simple graph wrote no
  meta.graph, so directed=False was lost and its mirror rows came back as
  two independent edges; {A->B, B->A} directed and {A-B} undirected were
  byte-identical. Undirected graphs now write meta.graph / directed false
  (as MultiGraph already did) and the loader skips the mirror it has
  already reconstructed. Directed output is unchanged, so the cross-port
  golden still holds.

- Float, bool and None were accepted as node ids, written as 1.5 / true /
  null, and then no edge to them resolved. Refused at add_node.

- NaN and infinity were written bare and read back as the strings "nan"
  and "inf". Refused with the new InvalidPropertyValueError wherever a
  property enters the graph.

Python 453 -> 498 tests, TS and JS 183 -> 221 each; all six ports still
agree on the canonical golden. Rust, C# and C++ hold string ids and do not
emit meta.graph yet - recorded in the changelog as the next parity item.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@maheshvaikri-code
maheshvaikri-code merged commit 14d7258 into main Nov 5, 2026
14 checks passed
@maheshvaikri-code
maheshvaikri-code deleted the fix/identity-contract-1.4.1 branch November 5, 2026 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant