Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modified AspNetCoreRequestAccessor to gracefully handle the absence of an HttpContext #18369

Conversation

AndyButland
Copy link
Contributor

@AndyButland AndyButland commented Feb 18, 2025

Prerequisites

  • I have added steps to test this contribution in the description below

Fixes: 18366

Description

The linked issue revealed an exception thrown after scheduled publishing, triggered via a notification handler implemented to provide warnings to the editor in the case of unrouteable content. This logic needs makes use of AspNetCoreRequestAccessor, that requires an HttpContext, which it doesn't have in scheduled publishing due to this running in a background task.

There is actually no reason to use GetRequiredHttpContext here as where it's used to retrieve the querystring or form value, it can correctly return a null value (as if there is no HttpContext, there's no Request and hence no querystring or form values).

To test here I've put a debugger in the notification handler, and successfully stepped through a scheduled publish operation with no exception.

Sorry, something went wrong.

…eable content when publishing in a background task.
@AndyButland AndyButland requested a review from Migaroez February 18, 2025 13:56
…for routeable content when publishing in a background task."

This reverts commit 953a795.
@Migaroez Migaroez changed the base branch from v15/dev to release/15.2.2 February 19, 2025 08:14
@Migaroez Migaroez changed the base branch from release/15.2.2 to v15/dev February 19, 2025 08:16
@AndyButland AndyButland changed the title Check for HttpContext before proceeding with editor warnings for routable content when publishing in a background task. Modified AspNetCoreRequestAccessor to gracefully handle the absence of an HttpContext Feb 19, 2025
@AndyButland AndyButland enabled auto-merge (squash) February 19, 2025 08:25
@AndyButland AndyButland merged commit f389cc9 into v15/dev Feb 19, 2025
20 of 21 checks passed
@AndyButland AndyButland deleted the v15/bugfix/fix-exception-thrown-with-scheduled-publishing-in-background-task branch February 19, 2025 08:46
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.

None yet

2 participants