Problem/Motivation
When invoked outside an interactive request, e.g. from drush, Drupal's request is null.
\Drupal\Core\Routing\CurrentRouteMatch::getCurrentRouteMatch assumes that it is not null, resulting in a fatal TypeError.
Steps to reproduce
For my case, this came up when rebuilding cache with a views_data_export view.
The route-building process elicited this error.
Proposed resolution
Check for a request before invoking getRouteMatch, and return an dummy/empty RouteMatch object if current reqeust is null.
Remaining tasks
Tests
User interface changes
None
Introduced terminology
None
API changes
None
Data model changes
None
Release notes snippet
Comments
Comment #2
quietone commentedIn Drupal core changes are made on on 11.x (our main development branch) first, and are then back ported as needed according to the Core change policies.
Comment #4
aaronbaumanComment #5
smustgrave commentedRan the test-only feature
IS is clear (thank you!)
Think returning NullRouteMatch is a good compromise.
LGTM.
Comment #6
mstrelan commentedLeft a comment, not changing status because it's a nit.
Comment #7
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #8
dcam commentedRestoring status after the rebase.
Comment #9
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #10
dcam commentedI don't know why the NR bot thought the patch couldn't be applied. I rebased the MR again to be sure.
Comment #13
catchThis looks reasonable. A bit surprised that we don't see it more often, but the test coverage shows it can happen.
Committed/pushed to 11.x, thanks!