Repository navigation
Keep a graph's meaning intact across dump and load (Python, JS, TS) - #1
Merged
Merged
Conversation
…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>
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.
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.:p:-1was resolved withstr.isdigit(), which has no sign, so the reference became the string"-1"and every edge to it raisedNodeNotFoundError— inISONGraph,MultiGraphand thequery()pattern parser-?[0-9]+as an integer and resolve against the loaded node table first, so a string id"-1"is still found as a stringmeta.graph, sodirected=Falsewas lost, its mirror rows came back as two independent edges, and{A->B, B->A}directed was byte-identical to{A-B}undirectedmeta.graphwithdirected false(asMultiGraphalready did); the loader reads it and skips the mirror it has already reconstructed. Directed graphs write nothing new1.5,TrueandNonewere accepted as node ids, written as1.5/true/null, and then no edge to them resolvedadd_nodewithInvalidIdentifierError. In JS/TS1.0is the integer1and stays acceptedfloat('nan')/infwere written bare and read back as the strings"nan"/"inf"InvalidPropertyValueError(aGraphError) onadd_node,add_edge,update_nodeand theProtectedGraphupdaters.update_nodenow also validates property namesVerification
tsc --noEmitclean.github/scripts/check_cross_port_goldens.py: all six ports agreeruff check: finding count identical tomainNot 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.graphfor an undirected graph. An undirected graph written by Python/JS/TS and read by those ports loads as directed, exactly as before. Recorded inCHANGELOG.mdas the next parity item.No version bump: the changelog entry sits under
[Unreleased]. PerCONTRIBUTING.mdthe bump, dated changelog, tag and publish dispatches follow the merge.🤖 Generated with Claude Code