Database update errors when upgrading from 1.5 to 2.1 pluginid not found

Created on 27 May 2023, about 1 year ago
Updated 8 May 2024, about 2 months ago

Problem/Motivation

I am doing an upgrade from 1.5 to 2.1.
composer can upgrade fine, after running drush updb it says I need to install flexible_permissions contrib module.

 --------- ------------- --------------- --------------------------------------                                                                                                                                                 
  Module    Update ID     Type            Description                                                                                                                                                                           
 --------- ------------- --------------- --------------------------------------                                                                                                                                                 
  group     9200          hook_update_n   9200 - Install required                                                                                                                                                               
                                          flexible_permissions contrib module.                                                                                                                                                  
  group     9201          hook_update_n   9201 - Update class name and handler                                                                                                                                                  
                                          class names for group_content_type.                                                                                                                                                   
  group     9202          hook_update_n   9202 - Update class name and handler                                                                                                                                                  
                                          class names for group_content.                                                                                                                                                        
  group     9203          hook_update_n   9203 - Update group_content DB                                                                                                                                                        
                                          table, fields and indexes.                                                                                                                                                            
  group     9204          hook_update_n   9204 - Remove the 'bypass group                                                                                                                                                       
                                          access' permission from all roles.                                    
  group     9205          hook_update_n   9205 - Convert group roles with the                                   
                                          'administer group' permission to                                      
                                          admin roles.                                                          
  group     9206          hook_update_n   9206 - Convert synchronized group                                     
                                          roles to new scope and target_role                                    
                                          structure.                                                            
  group     9207          hook_update_n   9207 - Convert default group roles                                    
                                          to new scope and target_role                                          
                                          structure.                                                            
  group     9208          hook_update_n   9208 - Convert user created group                                     
                                          roles to new scope and target_role                                    
                                          structure.                                                            
  group     9209          hook_update_n   9209 - Remove label and description                                   
                                          from relationship types.                                              
  group     9210          hook_update_n   9210 - Introduce the                                                  
                                          group_config_wrapper entity type.                                     
  metatag   remove_robo   post-update     Remove 'noydir', 'noodp' ROBOTS                                       
            ts_noydir_n                   options from meta tag entity fields.                                  
            oodp                                                                                                
  olivero   add_olivero   post-update     Sets the default                                                      
            _primary_co                   `base_primary_color` value of                                         
            lor                           Olivero's theme settings.                                             
 --------- ------------- --------------- --------------------------------------                 
 Do you wish to run the specified pending updates? (yes/no) [yes]:                                                                                                                                                              
 > yes
>  [notice] Update started: group_update_9200 
>  [error]  Update failed: group_update_9200
 [error]  Update aborted by: group_update_9200                                                                                                                                                                                  
 [error]  Finished performing updates.

After installing and trying again updb:

$ drush en flexible_permissions                                                                                                                                            
 [notice] Already enabled: flexible_permissions                                                                                                                                                                                 
$ drush updb                                                                                                                                                               
 [warning] Schema information for module flexible_permissions was missing from the database. You should manually review the module updates and your database to check if any updates have been skipped up to, and including, flexible_permissions_update_8000().
 --------- ------------- --------------- --------------------------------------                                                                                                                                                 
  Module    Update ID     Type            Description                                                                                                                                                                           
 --------- ------------- --------------- --------------------------------------                                                                                                                                                 
  group     9200          hook_update_n   9200 - Install required                                                                                                                                                               
                                          flexible_permissions contrib module.                                                                                                                                                  
  group     9201          hook_update_n   9201 - Update class name and handler                                                                                                                                                  
                                          class names for group_content_type.                                                                                                                                                   
  group     9202          hook_update_n   9202 - Update class name and handler                                                                                                                                                  
                                          class names for group_content.                                                                                                                                                        
  group     9203          hook_update_n   9203 - Update group_content DB                                                                                                                                                        
                                          table, fields and indexes.                                                                                                                                                            
  group     9204          hook_update_n   9204 - Remove the 'bypass group                                                                                                                                                       
                                          access' permission from all roles.                                    
  group     9205          hook_update_n   9205 - Convert group roles with the                                   
                                          'administer group' permission to                                      
                                          admin roles.                                                          
  group     9206          hook_update_n   9206 - Convert synchronized group                                     
                                          roles to new scope and target_role                                    
                                          structure.                                                            
  group     9207          hook_update_n   9207 - Convert default group roles                                    
                                          to new scope and target_role                                          
                                          structure.                                                            
  group     9208          hook_update_n   9208 - Convert user created group                                     
                                          roles to new scope and target_role                                    
                                          structure.                                                            
  group     9209          hook_update_n   9209 - Remove label and description                                   
                                          from relationship types.                                              
  group     9210          hook_update_n   9210 - Introduce the                                                  
                                          group_config_wrapper entity type.                                     
  metatag   remove_robo   post-update     Remove 'noydir', 'noodp' ROBOTS                                       
            ts_noydir_n                   options from meta tag entity fields.                                  
            oodp                                                                                                
  olivero   add_olivero   post-update     Sets the default                                                      
            _primary_co                   `base_primary_color` value of                                         
            lor                           Olivero's theme settings.                                             
 --------- ------------- --------------- --------------------------------------                                 

 Do you wish to run the specified pending updates? (yes/no) [yes]:                                              
 > yes                                                  
>  [notice] Update started: group_update_9200           
>  [notice] Update completed: group_update_9200         
>  [notice] Update started: group_update_9201           
>  [notice] Update completed: group_update_9201         
>  [notice] Update started: group_update_9202           
>  [notice] Update completed: group_update_9202         
>  [notice] Update started: group_update_9203           
>  [error]  Call to a member function getPluginId() on null                                                     
>  [error]  Update failed: group_update_9203            
>  [error]  Update aborted by: group_update_9203 

If trying to update using update.php:

PHP message: Error: Call to a member function getPluginId() on null in /web/modules/contrib/group/src/Entity/Storage/GroupRelationshipStorage.php on line 74 #0 /web/core/lib/Drupal/Core/Entity/Sql/SqlFieldableEntityTypeListenerTrait.php(213): Drupal\group\Entity\Storage\GroupRelationshipStorage->restore()
#1 /web/core/lib/Drupal/Core/Entity/Sql/SqlFieldableEntityTypeListenerTrait.php(69): Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema->copyData()
#2 /web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php(446): Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema->traitOnFieldableEntityTypeUpdate()
#3 /web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php(1525): Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema->onFieldableEntityTypeUpdate()
#4 /usr" while reading response header from upstream

Obviously as updatedb failed when going to admin/content :

"PHP message: Uncaught PHP Exception Drupal\Core\Database\DatabaseExceptionWrapper: "SQLSTATE[42S02]: Base table or view not found: 1146 Table 'dev_crel_d9.group_relationship_field_data' doesn't exist: SELECT DISTINCT "gc"."plugin_id" AS "plugin_id"
FROM
"group_relationship_field_data" "gc"
WHERE "plugin_id" IN (:db_condition_placeholder_0, :db_condition_placeholder_1, :db_condition_placeholder_2, :db_condition_placeholder_3, :db_condition_placeholder_4, :db_condition_placeholder_5, :db_condition_placeholder_6, :db_condition_placeholder_7, :db_condition_placeholder_8, :db_condition_placeholder_9, :db_condition_placeholder_10, :db_condition_placeholder_11, :db_condition_placeholder_12, :db_condition_placeholder_13, :db_condition_placeholder_14, :db_condition_placeholder_15, :db_condition_placeholder_16, :db_condition_placeholder_17, :db_condition_placeholder_18, :db_condition_placeholder_19, :db_condition_placeholder_20, :db_condition_placeholder_21, :db_condition_placeholder_22, :db_condition_place" while reading response header from upstream,  request: "GET /ca/admin/content

Also obvioulsy going to admin/group:

"PHP message: Uncaught PHP Exception Drupal\Core\Entity\Query\QueryException: "'plugin_id' not found" at /usr/local/projects/dev.catalunyareligio.cat/web/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php line 369"

πŸ› Bug report
Status

Active

Version

2.1

Component

Code

Created by

πŸ‡ͺπŸ‡ΈSpain aleix

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

Comments & Activities

  • Issue created by @aleix
  • πŸ‡ͺπŸ‡ΈSpain aleix

    It was a faulty record in tables group_content_field_data and group_content_field_data. Removing these entries makes updatedb fine.

    So I think this could be closed

  • Status changed to Closed: works as designed about 1 year ago
  • Status changed to Active 11 months ago
  • πŸ‡¦πŸ‡ΉAustria ViNCE
  • πŸ‡¦πŸ‡ΉAustria ViNCE

    I'm facing the same problem.

    [notice] Update started: group_update_9203
    [error]  Call to a member function getPluginId() on null
    [error]  Update failed: group_update_9203
    

    Already spent half a day and a night to try different ways. Already having several thousand entries in the database. Couldn't find a way to filter out faulty ones.
    Any ideas how to either:

    • filter out and remove faulty entries?
    • or change the update code in a way not ending up in a fatal error?

    the actual code in group.install is:

    function group_update_9203(&$sandbox) {
      $definition_update_manager = \Drupal::entityDefinitionUpdateManager();
      $last_installed_schema_repository = \Drupal::service('entity.last_installed_schema.repository');
      assert($last_installed_schema_repository instanceof EntityLastInstalledSchemaRepositoryInterface);
    
      // Update the database tables.
      $entity_type = $definition_update_manager->getEntityType('group_content');
      $entity_type->set('base_table', 'group_relationship');
      $entity_type->set('data_table', 'group_relationship_field_data');
    
      // Add the plugin_id and group_type field.
      $field_storage_definitions = $last_installed_schema_repository->getLastInstalledFieldStorageDefinitions('group_content');
      $field_storage_definitions['plugin_id'] = BaseFieldDefinition::create('string')
        ->setName('plugin_id')
        ->setTargetEntityTypeId('group_content')
        ->setTargetBundle(NULL)
        ->setLabel(t('Plugin ID'))
        ->setRequired(TRUE)
        ->setReadOnly(TRUE)
        ->setInitialValue('TEMP')
        ->setProvider('group');
    
      $field_storage_definitions['group_type'] = BaseFieldDefinition::create('entity_reference')
        ->setName('group_type')
        ->setTargetEntityTypeId('group_content')
        ->setTargetBundle(NULL)
        ->setLabel(t('Group type'))
        ->setSetting('target_type', 'group_type')
        ->setRequired(TRUE)
        ->setReadOnly(TRUE)
        ->setInitialValue('TEMP')
        ->setProvider('group');
    
      // Update the fields and regenerate indexes, the correct initial values will
      // be retrieved from GroupRelationshipStorage::restore().
      $definition_update_manager->updateFieldableEntityType($entity_type, $field_storage_definitions, $sandbox);
    }
    
  • Hello @ViNCE,

    I am facing an issue on the same hook. The error is "Langcode is missing". For me the field definition ($field_storage_definitions) is empty when I try to debug it in a preprocess. So obviously the Langcode field is missing for a translatable array.

    I had tried to set these just before by using :

    $storage_definitions = $entityFieldManager->getFieldStorageDefinitions('group_content');
    $last_installed_schema_repository->setLastInstalledFieldStorageDefinitions('group_content',$storage_definitions);
    

    And then it shows me other errors.
    SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'entity_id' cannot be null: INSERT INTO "tmp_4e14aegroup_relationship_field_data"

    it seems that it has loop over some database entries because there is some warning that are repeated before :

      [warning] Undefined array key "plugin_id" SqlContentEntityStorage.php:597
      [warning] Undefined array key "group_type" SqlContentEntityStorage.php:597

    Il your storage definition empty ?
    Does the hook seems to process some items and one is failing or it fails at the beginning ?

  • Hi,

    I use res-ben code ✨ Entities identified by strings as group content Closed: won't fix to properly uninstall patch "2797793-279.patch".
    This code populates 'entity_id' column during the process.

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

    @aleix - I realize your comment at #3 is five months old, but do you recall how you identified the 'faulty records' in tables group_content_field_data and group_content that needed removing?

  • πŸ‡ͺπŸ‡ΈSpain aleix

    Cannot recall exactly, but looking the tables I think that it was some non existing entity somewhere indexed in this table, If you have not too much entries check these id's. Or better use dpm or xdebug breakpoint to check which id is failing...

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

    Many thanks @aleix - it turned out we had left behind some rows in the group_content table that referenced items that were (at one point) found in the group_content__entity_id_str table to support the essentially defunct groupmenu module. We removed references to those items in both group_content_field_data and group_content tables and we stopped having this issue. (We have moved away from groupmenu and are adopting group_content_menu - but getting out from under the patch from https://www.drupal.org/project/group/issues/2797793 ✨ Entities identified by strings as group content Closed: won't fix was a bear.)

  • It turned out we also had left behind some rows in the following database tables

    • group_content
    • group_content_field_data

    I ran some comparisons using the YML file to determine which rows I need to delete. The YML files for these content types have names like group.content_type.group_content_type_1123kl123lkzz.yml

    If you have orphaned data you might find out which type or bundle rows need to be deleted based on the group content type config files you have.

    Once you have determined the orphaned rows, you can run some database delete queries.

    \Drupal::database()->delete('group_content')
        ->condition('type', 'group_content_type_1123kl123lkzz', '=')
        ->execute();
    
    \Drupal::database()->delete('group_content_field_data')
        ->condition('type', 'group_content_type_1123kl123lkzz', '=')
        ->execute();
    
Production build 0.69.0 2024