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

Issue fork drupal-3536072

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

aaronbauman created an issue. See original summary.

quietone’s picture

Version: 11.2.x-dev » 11.x-dev

In 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.

smustgrave’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Ran the test-only feature

1) Drupal\Tests\Core\Routing\CurrentRouteMatchTest::testGetCurrentRouteObject
TypeError: Drupal\Core\Routing\CurrentRouteMatch::getRouteMatch(): Argument #1 ($request) must be of type Symfony\Component\HttpFoundation\Request, null given, called in /builds/issue/drupal-3536072/core/lib/Drupal/Core/Routing/CurrentRouteMatch.php on line 87
/builds/issue/drupal-3536072/core/lib/Drupal/Core/Routing/CurrentRouteMatch.php:99
/builds/issue/drupal-3536072/core/lib/Drupal/Core/Routing/CurrentRouteMatch.php:87
/builds/issue/drupal-3536072/core/tests/Drupal/Tests/Core/Routing/CurrentRouteMatchTest.php:80
ERRORS!
Tests: 10, Assertions: 25, Errors: 1, PHPUnit Deprecations: 11.
Exiting with EXIT_CODE=2

IS is clear (thank you!)

Think returning NullRouteMatch is a good compromise.

LGTM.

mstrelan’s picture

Left a comment, not changing status because it's a nit.

needs-review-queue-bot’s picture

Status: Reviewed & tested by the community » Needs work
StatusFileSize
new91 bytes

The 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.

dcam’s picture

Status: Needs work » Reviewed & tested by the community

Restoring status after the rebase.

needs-review-queue-bot’s picture

Status: Reviewed & tested by the community » Needs work
StatusFileSize
new91 bytes

The 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.

dcam’s picture

Status: Needs work » Reviewed & tested by the community

I don't know why the NR bot thought the patch couldn't be applied. I rebased the MR again to be sure.

  • catch committed 3cca82d6 on 11.x
    Issue #3536072 by aaronbauman, smustgrave, mstrelan: CurrentRouteMatch::...

catch’s picture

Status: Reviewed & tested by the community » Fixed

This 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!

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.