Fix #1194: Fix _remove_circular_references nulling shared non-circular config values - #1195
Open
pamod-madubashana wants to merge 1 commit into
Open
pamod-madubashana wants to merge 1 commit into
pamod-madubashana wants to merge 1 commit into
Conversation
…ared non-circular config values
pamod-madubashana
marked this pull request as ready for review
September 18, 2026 15:33
This branch has not been deployed
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.
Fixes #1194
PR Summary — Fix
_remove_circular_referencesnulling shared non-circular config values (Issue #1194)What changed
pdf2zh/config.py—ConfigManager._remove_circular_references:seenset is now scoped to the current recursion (ancestor) path instead of onenever-shrunk global set for the whole traversal. Container ids are added before
recursing into children and discarded (
seen.discard) in afinallyblock whenrecursion unwinds, so a diamond (shared but non-circular) reference is preserved
while a true ancestor-path cycle still collapses to
None.dictandlistcontainers. Previously every object(including immutable scalars like small ints/strings, which share identity via
interning) was added to
seen, so e.g.[1, 1]would have serialized as[1, None]. Scalars are now returned verbatim.Why it addresses the issue
The issue's repro returned
{'x': {'a': 1}, 'y': None}for a shared dict referencedfrom two sibling keys (and
[[1, 2], None]for a shared list), causing silent dataloss on
_save_config. After the fix, both cases round-trip fully, while a genuineself-referential dict (
d["self"] = d) still collapses to{"self": None}asintended, and nested cycles (e.g. a self-referential list inside a dict) still
collapse at the exact cyclic edge.
Verification
repeated immutable scalars, nested list cycle): all assertions passed.
Command:
python3 _repro_1194.py(temporary script, removed after the run).Result:
ALL REPRO CHECKS PASSED.python3 -m py_compile pdf2zh/config.py— passed with no output.pytest .per.github/workflows/python-test.yml) couldnot be run here: neither
pytestnoruvis installed in this environment, and thesuite additionally requires system dependencies (libreoffice) and network-cached
BabelDOC assets. There are no existing tests covering
ConfigManager, so nonarrower test target exists.