Skip to content

Enhance context management by adding methods to refresh and clone ClientContext, ensuring proper handling of pending requests.#5308

Merged
gautamdsheth merged 3 commits intodevfrom
fix/context-issue
May 5, 2026
Merged

Enhance context management by adding methods to refresh and clone ClientContext, ensuring proper handling of pending requests.#5308
gautamdsheth merged 3 commits intodevfrom
fix/context-issue

Conversation

@gautamdsheth
Copy link
Copy Markdown
Collaborator

Before creating a pull request, make sure that you have read the contribution file located at

https://github.com/pnp/powerShell/blob/dev/CONTRIBUTING.md

Type

  • Bug Fix
  • New Feature
  • Sample

Related Issues?

Fixes #X, partially fixes #Y, mentioned in #Z, etc.

What is in this Pull Request ?

Please describe the changes in the PR.

Guidance

  • You can delete this section when you are submitting the pull request.*
  • Please update this PR information accordingly. We use this as part of our release notes in monthly communications.
  • Please target your PR to Dev branch. If you do not target the Dev branch we will not accept this PR.

…entContext, ensuring proper handling of pending requests.
Copilot AI review requested due to automatic review settings May 2, 2026 09:23
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the SharePoint connection/context plumbing to proactively handle leftover pending CSOM requests by refreshing (cloning) the ClientContext before executing most SharePoint cmdlets, with an opt-out for Invoke-PnPQuery.

Changes:

  • Add a base-cmdlet hook (ShouldRefreshContextWithPendingRequest) and refresh the connection context during BeginProcessing when pending CSOM requests are detected.
  • Introduce PnPConnection.RefreshContext* helpers plus cache replacement logic, and ensure CloneContext() clones if a cached context has pending requests.
  • Disable the auto-refresh behavior for Invoke-PnPQuery so it can execute pending CSOM requests.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/Commands/Base/PnPSharePointCmdlet.cs Refreshes the connection ClientContext at cmdlet start when pending requests exist; adds an overridable hook.
src/Commands/Base/PnPConnection.cs Adds context refresh/clone helpers and updates context cache behavior to handle pending requests.
src/Commands/Base/InvokeQuery.cs Opts out of context refresh so pending CSOM requests can be executed.

Comment thread src/Commands/Base/PnPConnection.cs
Comment thread src/Commands/Base/PnPSharePointCmdlet.cs
Comment thread src/Commands/Base/PnPSharePointCmdlet.cs
…nd adding ShouldRefreshContextWithPendingRequest property to manage pending CSOM requests.
@gautamdsheth gautamdsheth merged commit 38e9dd4 into dev May 5, 2026
3 checks passed
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.

2 participants