Skip to content

Fix pickling modules with cyclic references - #615

Open
David-the-happy-piglet wants to merge 1 commit into
cloudpipe:masterfrom
David-the-happy-piglet:fix/module-by-value-cycles
Open

David-the-happy-piglet wants to merge 1 commit into
cloudpipe:masterfrom
David-the-happy-piglet:fix/module-by-value-cycles

Conversation

@David-the-happy-piglet

Copy link
Copy Markdown

Serializing a module by value fails with PicklingError: Could not pickle object as excessively deep recursion required when its state refers back to the module, including through circular package imports. Functions referencing such a package also fail to serialize.

Restore module state after construction so pickle can memoize the module before traversing back-references. Keep the existing reconstruction helper and by-reference behavior. Add regressions for self-references, aliases, circular packages and functions using them, including fresh-process round trips with protocols 2, 4 and 5.

Validation on macOS arm64:

  • The 12 new regressions fail before the fix and pass afterward.
  • CPython 3.12: 278 passed, 10 skipped, 2 xfailed (baseline: 266 passed, 10 skipped, 2 xfailed).
  • CPython 3.14: 275 passed, 13 skipped, 2 xfailed.
  • PyPy 3.9: 29 selected tests passed.
  • Baseline/current payload compatibility checks pass for protocols 2, 4 and 5.
  • Pre-commit passes for the changed files. The all-files run reports a pre-existing Black formatting difference in untouched tests/cloudpickle_ipykernel_test.py; that formatting is not included.

Windows, Linux and downstream Dask/Ray suites were not run.

This branch has not been deployed

No deployments
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