Problem/Motivation

This is an edge case, but we semi-frequently see random fails in our tests (which check php dblog messages after each scenario) like this:

Error: Call to a member function getDisplayName() on null in Drupal\navigation\Plugin\Block\NavigationUserBlock::buildLinks() (line 65 of ..../web/core/modules/navigation/src/Plugin/Block/NavigationUserBlock.php)

According to the test fail, this happens on 404 request from an image, so fairly delayed. I think what's happening is that the behat test cleanup is already deleting the user before the request gets to that point and then the user essentially vanishes mid-request.

Steps to reproduce

Proposed resolution

A quickfix would be to just check if the user was loaded and if not, return early.

Alternatively, the block could add a context requirement on the current user, which would automatically take care of the cache dependency.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3560876

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

berdir created an issue. See original summary.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

berdir’s picture

Status: Active » Needs review

This is an edge case that I don't think is worth testing for, but it happens surprisingly often for us in our behat tests.

I didn't try the plugin context route, plugin contexts didn't really work for me with a custom block in a project, didn't investigate further.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Changes seems small enough don't believe need explicit test coverage for.

  • lauriii committed 7ef42dab on 11.x
    chore: #3560876 NavigationUserBlock::buildLinks() doesn't check if the...

  • lauriii committed 14f5b68d on 11.3.x
    chore: #3560876 NavigationUserBlock::buildLinks() doesn't check if the...

lauriii’s picture

Status: Reviewed & tested by the community » Fixed

Thank you!

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

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

Maintainers, credit people who helped resolve this issue.

  • lauriii committed d2246d5e on main
    chore: #3560876 NavigationUserBlock::buildLinks() doesn't check if the...

Status: Fixed » Closed (fixed)

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