Skip to content

Preserve session stubs when deep-copying managed objects - #1118

Closed
Shubham-Padkonde wants to merge 1 commit into
vmware:masterfrom
Shubham-Padkonde:fix/session-stub-deepcopy
Closed

Shubham-Padkonde wants to merge 1 commit into
vmware:masterfrom
Shubham-Padkonde:fix/session-stub-deepcopy

Conversation

@Shubham-Padkonde

Copy link
Copy Markdown

Fixes #1093.

Deep-copying a managed object backed by VimSessionOrientedStub currently reaches the session's thread lock and raises TypeError: cannot pickle '_thread.lock' object. The underlying SoapStubAdapter already returns itself from __deepcopy__.

Apply that same identity-preserving behavior to SessionOrientedStub. Copied managed/data objects retain their original live session, lock and login state; the copy does not log in or create an independent connection.

Regression tests cover the base and vim-specific session stubs, a ServiceInstance, and a ServiceContent whose managed-object fields share the same session. The data object remains independently editable.

Validation on Windows, Python 3.12.6:

  • Before the production change, all four new cases failed on the thread lock.
  • python -m unittest discover tests: 41 tests passed, using the repository's pinned mock 5.2.0 and vcrpy 7.0.0 dependencies.
  • git diff --check passed.

The existing HTTP tests use recorded fixtures. No live vCenter/ESXi validation was performed.

Prepared and tested with OpenAI Codex assistance.

@legal-compliance-bot

Copy link
Copy Markdown

🛑 Legal Compliance Check Failed

Hi @Shubham-Padkonde, thank you for your contribution!

To merge this Pull Request, you must sign our DCO.

Note: Even if you signed off your commits locally (using git commit -s), you must post the comment below to register your signature with our automated system.
Note: This is a one-time process. Once signed, future contributions to this repository will be verified automatically.

1. Read the Document: Click here to read the DCO
2. Sign via Comment: Copy and paste the exact line below into a new comment on this Pull Request:

I have read the DCO Document and I hereby sign the DCO for this and all future contributions.

⏳ Processing Schedule:
Our 'Compliance Sweeper' runs automatically approximately every 15-20 minutes.
After you post the comment, your status will update automatically during the next scheduled run.
You do not need to take any further action.

@Shubham-Padkonde

Copy link
Copy Markdown
Author

I have read the DCO Document and I hereby sign the DCO for this and all future contributions.

Fixes vmware#1093. Match SoapStubAdapter identity semantics so copies retain the live session instead of trying to pickle its lock.

Signed-off-by: Shubham Padkonde <shubhampadkonde12@gmail.com>
@Shubham-Padkonde
Shubham-Padkonde force-pushed the fix/session-stub-deepcopy branch from 438b876 to d606340 Compare October 2, 2026 13:29
@DanielDraganov

Copy link
Copy Markdown
Collaborator

Thanks for the fix and the thorough tests, @Shubham-Padkonde, and for tracking down the cause of #1093.
We're no longer accepting pull requests on this repository, so we won't be merging this. The issue will be fixed in the next major pyVmomi release. Please follow #1093 for updates. Closing this PR.

@DanielDraganov

DanielDraganov commented Oct 8, 2026 •

Copy link
Copy Markdown
Collaborator

Hi @Shubham-Padkonde.
Could you share your specific use case for deep copying stubs?

A stub adapter manages underlying connection state, sockets, and session data, making a standard Python deepcopy problematic and incomplete. Because of this, we are evaluating whether it makes more sense to deprecate or remove the existing deepcopy implementation on stubs entirely rather than extending it further.

Knowing the specific workflow or issue you are addressing will help us determine the best alternative or architectural path forward. Thanks!

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.

copy.deepcopy() fails when using a SessionOrientedStub

2 participants