Problem/Motivation

When the Webprofiler module is enabled I have problems when updating schema of entities (adding/removing fields) like by example enabling translations for menu link content entity. Once enabled translations for that entity, I get an error when trying to create a menu link from the menu UI. Copying part of the exception below.
Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'content_translation_source' in 'field list': INSERT INTO {menu_link_content_data} ...
The menu_link_content_data did not get updated after enable the translation on the UI. So after debugging I found some clues and got to the following conclusion.

When Webprofiler module is enabled it overrides the entity_type.manager core service to mainly override the getStorage method and provide custom classes for some entity types.
As part of the getStorage method, the entity type handlers are stored in the "loaded" property for performance. The core entity type manager do that as well but it clears the stored references in the "clearCachedDefinitions" method. This clearing is not happening in the Webprofiler entity type manager wrapper clearCachedDefinitions method and in the middle of enabling the translations for an entity, the definitions are cleared by calling clearCachedDefinitions which is not clearing the "loaded" array and then when retrieving some entity storage handler by getStorage it is providing and outdated handler and then the supposed updated entity schema is not updated in the database.

Steps to reproduce for D8 core 8.6.13 and Devel 8.x-2.0:
1. Install a site with standard profile.
2. Enable devel, webprofiler, language and content_translation modules.
4. Go to "admin/config/regional/content-language" and enable translations for "Custom menu link".
5. Go to "admin/structure/menu/manage/main/add" and add a link to the main menu.
6. You should get the error when saving. You can check the logs for more information about it.

Proposed resolution

I think that as core entity type manager clears the stored handler references, webprofiler entity type manager wrapper should clear loaded and rendered properties as well.

Remaining tasks

Will provide the patch.

User interface changes

none

API changes

none

Data model changes

none

Release notes snippet

none

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

emacoti created an issue. See original summary.

emacoti’s picture

Status: Active » Needs review
FileSize
526 bytes

Here is the patch.

  • lussoluca committed ce38efb on 8.x-2.x authored by emacoti
    Issue #3044500 by emacoti: Webprofiler is breaking entity updates when...
lussoluca’s picture

Status: Needs review » Fixed

Yes, you are right.

Committed and pushed to 8.x-2.x
Thanks!

Status: Fixed » Closed (fixed)

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