Mismatched entity and/or field definitions

Created on 28 June 2021, over 3 years ago
Updated 5 February 2023, almost 2 years ago

Problem/Motivation

When update to version 2.0.0 and have link_override already in use, the entity is not update correctly

Mismatched entity and/or field definitions
The following changes were detected in the entity type and field definitions.
Custom menu link
The Link override field needs to be updated

Steps to reproduce

  1. Update module from version 1.2 to 2.0.0
  2. Try to run drush updb
  3. No update is available
  4. Enter on status report

Proposed resolution

Create a hook_update to update FieldStorageDefinition

πŸ› Bug report
Status

Needs review

Version

2.0

Component

Code

Created by

πŸ‡§πŸ‡·Brazil faline

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

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡΅πŸ‡±Poland jsobiecki Wroclaw

    Hi guys, I redundantly created MR for different bug that fixes different bug ( https://www.drupal.org/project/translatable_menu_link_uri/issues/3259442 πŸ› Notice: Undefined index: link_override__title in Drupal\Core\Entity\Sql\SqlContentEntityStorage->loadFromSharedTables Fixed ) by fixing entity mismatch issue. So probably this patch will not gonna be merged, as the one in this ticket is redundant. I overlooked this issue when worked on #3259442.

    Thank you for all your work, I'll add people involved here to credits when I'll merge fix for #3259442.

  • πŸ‡΅πŸ‡±Poland krystianbuczak

    Version 2 of the module provided the setRevisionable(TRUE) flag in a hook_entity_base_field_info(). In documentation block of this hook we can read:

    Field (storage) definitions returned by this hook must run through the regular field storage life-cycle operations: they need to be properly installed, updated, and uninstalled. This would typically be done through the Entity Update API provided by the entity definition update manager.

    Looks like no proper database updates are executed and field storage must be updated another way.

    An example post update action for Menu link content can be found here: https://api.drupal.org/api/drupal/core%21modules%21menu_link_content%21m...

    Similar to the linked function appropriate update script can be placed in hook_update_n() and minimal version that should work could be like:

    function translatable_menu_link_uri_update_9001(&$sandbox) {
      try {
        $definition_update_manager = \Drupal::entityDefinitionUpdateManager();
        $last_installed_schema_repository = \Drupal::service('entity.last_installed_schema.repository');
        $entity_type = $definition_update_manager
          ->getEntityType('menu_link_content');
        $field_storage_definitions = $last_installed_schema_repository
          ->getLastInstalledFieldStorageDefinitions('menu_link_content');
        $field_storage_definitions['link_override']->setRevisionable(TRUE);
        $definition_update_manager
          ->updateFieldableEntityType($entity_type, $field_storage_definitions, $sandbox);
      }
      catch (Throwable $e) {
        watchdog_exception('translatable_menu_link_uri', $e);
      }
    }
    

    This way API should also take care of proper table columns what can be verified by the command describe menu_link_content_field_revision;:
    +-------------------------------+------------------+------+-----+---------+-------+
    | Field | Type | Null | Key | Default | Extra |
    +-------------------------------+------------------+------+-----+---------+-------+
    ...
    | link_override__uri | varchar(2048) | YES | MUL | NULL | |
    | link_override__title | varchar(255) | YES | | NULL | |
    | link_override__options | longblob | YES | | NULL | |
    +-------------------------------+------------------+------+-----+---------+-------+

  • πŸ‡²πŸ‡©Moldova sdstyles

    Created a patch with solution from #20 which applies to 2.0 tag

  • πŸ‡ΊπŸ‡ΈUnited States chambers

    I added patch #21 and ran drush updb and no issues, error went away.

  • First commit to issue fork.
  • Status changed to RTBC over 1 year ago
  • πŸ‡ΊπŸ‡¦Ukraine ankondrat4 Lutsk

    Hello.

    Patch #21 works as expected. Reviewed and added screenshot.
    I have created fork and MR for adding these changes to next release of module.

  • πŸ‡©πŸ‡ͺGermany sgurlt

    The issue also exists for D10 and V2.1.0

    For some reason, #21 did not apply for me correctly for Version 2.1.0 of the module.
    I simply recreated it based on the 2.1.0 and it started working :-)

  • πŸ‡©πŸ‡ͺGermany thomaswalther Rhein-Main Area

    #19 worked for me:

    Change the content of the file translatable_menu_link_uri.install:
    https://git.drupalcode.org/issue/translatable_menu_link_uri-3259442/-/bl...

    Code is not in the 2.1. or @dev

  • First commit to issue fork.
  • πŸ‡΅πŸ‡±Poland jsobiecki Wroclaw

    Change commited. Thank you all people involved in this thread! I updated last patch with removal of deprecated (in D10) code for exception handling and replcaed it with proper solution for D10 and latter....

Production build 0.71.5 2024