Skip to content

Disable automatic use of pickle in ComponentUID - #4105

Merged
blnicho merged 8 commits into
Pyomo:mainfrom
jsiirola:disable-pickle
Nov 19, 2026
Merged

blnicho merged 8 commits into
Pyomo:mainfrom
jsiirola:disable-pickle

Conversation

@jsiirola

@jsiirola jsiirola commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Fixes # .

NOTE: this is not backwards compatible: users who put custom types into indices and then use ComponentUID will need to either re-enable pickle, or register their own serializer/deserializer.

Summary/Motivation:

This PR disables the automatic use of pickle when generating / restoring string representations of ComponentUID objects. We still support arbitrary classes in component indexes, however users will need to register callback functions to handle the serialization / deserialization action.

Users can restore previous behavior by setting ComponentUID.EnablePickle = True

Changes proposed in this PR:

  • Add ComponentUID.EnablePickle to control if ComponentUID string representations can use pickle for unknown types
  • Add ComponentUID.Serializer so users can register custom string serialization / deserialization functions
  • Rework pickle imports so that they can be deferred until they are actually needed.
  • Test the new functionality

AI-Use Disclosure

  • AI tools were NOT used during the preparation of this PR

or

  • AI tools contributed to the development of this PR

    • AI tools generated documentation (including the PR description/comments, code comments, and/or Sphinx documentation)
    • AI tools generated tests (baselines, examples, and/or code)
    • AI tools generated code (apart from tests)

    Review process (select ONE):

    • Rewritten: All AI-generated content was rewritten by me before being committed.
    • Reviewed/verified: I retained AI-generated content and verified it before committing. Verification included (as applicable):
      • Ran the code and fixed issues
      • Added and ran tests
      • Checked correctness/logic of code and tests
      • Checked for alignment with the contribution guide
      • Considered security implications
    • As-is: AI-generated content was commited directly to the repository

Notes for reviewers (optional):

Legal Acknowledgement

By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution:

  1. I agree my contributions are submitted under the BSD license.
  2. I represent I am authorized to make the contributions and grant the license. If my employer has rights to intellectual property that includes these contributions, I represent that I have received permission to make contributions and grant the required license on behalf of that employer.

Comment on lines +819 to +821
# Note that the pickle string for namedtuple changes between
# Python 2, 3, and pypy, so we will just check the non-pickle
# data part

@mrmundt mrmundt Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will NOT let this hold anything up but are we sure any of this nonsense is still accurate given changes in Python 3 and pypy and the overall Python ecosystem? References to Python 2 make me suspicious

@mrmundt mrmundt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We love deferred imports!

@github-project-automation github-project-automation Bot moved this from Todo to Reviewer Approved in November 2026 Release Nov 18, 2026
@codecov

codecov Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.30%. Comparing base (2109c73) to head (2e1abe8).
⚠️ Report is 11 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4105   +/-   ##
=======================================
  Coverage   90.29%   90.30%           
=======================================
  Files         920      920           
  Lines      109601   109616   +15     
=======================================
+ Hits        98969    98988   +19     
+ Misses      10632    10628    -4     
Flag Coverage Δ
builders 29.13% <54.54%> (+<0.01%) ⬆️
default 86.50% <100.00%> (?)
expensive 35.23% <54.54%> (?)
linux 87.84% <100.00%> (-1.96%) ⬇️
linux_other 87.84% <100.00%> (+<0.01%) ⬆️
oldsolvers 28.03% <54.54%> (+<0.01%) ⬆️
osx 83.28% <100.00%> (+<0.01%) ⬆️
win 85.56% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@blnicho
blnicho merged commit 12c5c70 into Pyomo:main Nov 19, 2026
64 of 67 checks passed
@github-project-automation github-project-automation Bot moved this from Reviewer Approved to Done in November 2026 Release Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects

Development

Successfully merging this pull request may close these issues.

3 participants