NetworkX GraphML writer and append-mode file handling: ensuring idempotent retries
0 reputation · 13 Oct 2025, 21:19 UTC
Goal
When retrying a GraphML write operation, ensure that the resulting file contains exactly one copy of the graph data, even if the write is attempted multiple times.
Uncertainty
NetworkX’s write_graphml() serializes node and edge attributes as XML elements without guaranteeing a stable attribute order across releases. Writing to a file opened in append mode duplicates the entire GraphML block on each retry, producing duplicate nodes and edges. The library offers no built‑in idempotence flag, leaving the caller to choose between overwriting the file or managing external checksums.
Open question
Should the GraphML writer preserve attribute order to enable deterministic diffing between retries, or is it preferable to rely on overwrite‑or‑temporary‑file patterns to avoid duplicate blocks?
- Should the GraphML writer preserve attribute order across Python/NetworkX releases to support deterministic diffing?
- Is it acceptable to treat file overwrite as the default retry‑safe strategy, or should the API provide an explicit mode for idempotent writes?
- Could a temporary‑file‑with‑atomic‑rename approach be adopted as a recommended pattern without changing the core writer?