Fix workspace-support check in entity queries

Created on 20 October 2023, about 1 year ago
Updated 4 January 2024, 11 months ago

Problem/Motivation

When a module provides base fields for the User entity type, and uses an entity query in hook_entity_base_field_info() to determine them, the site will get into an infinite loop when clearing caches:
- the entity field manager tries to build the list of field definitions for the User entity type
- the custom hook_entity_base_field_info() implementation will start an entity query
- \Drupal\workspaces\EntityQuery\QueryTrait::prepare() checks whether there's an active workspace
- \Drupal\workspaces\Negotiator\SessionWorkspaceNegotiator::applies() tries to check whether the current user is authenticated
- \Drupal\Core\Session\AccountProxy::getAccount() will try to load the user entity, and eventually ends up trying to build the list of field definitions again

Proposed resolution

Swap the order of the conditions in \Drupal\workspaces\EntityQuery\QueryTrait::prepare().

This fixes the problem because the User entity type can not be supported by workspaces (not revisionable nor publishable), so the isEntityTypeSupported() check will return FALSE and it won't advance to the following hasActiveWorkspace() check.

Remaining tasks

Review.

User interface changes

Nope.

API changes

Nope.

Data model changes

Nope.

Release notes snippet

Nope.

🐛 Bug report
Status

Fixed

Version

10.2

Component
Workspaces 

Last updated 3 days ago

No maintainer
Created by

🇷🇴Romania amateescu

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024