Error after upgrade from 3.0.4 to 3.1.2: 'lp_status' not found

Created on 17 September 2024, 3 months ago

Problem/Motivation

After upgrading from 3.0.4 to 3.1.2, when trying to visit a course, an error is displayed:

Drupal\Core\Entity\Query\QueryException: 'lp_status' not found in Drupal\Core\Entity\Query\Sql\Tables->ensureEntityTable() (line 369 of core/lib/Drupal/Core/Entity/Query/Sql/Tables.php).

After reviewing the .install file of the module, I see that it was included in the hook_install of the module if the lp_status definition exists:

  // Checking if the lp_status fields definition is not exist.
  // In case of the fresh install, according to order of the modules
  // installation, the opigno_module can be enabled before this one.
  $definition_update_manager = \Drupal::entityDefinitionUpdateManager();
  if (!($definition_update_manager->getFieldStorageDefinition('lp_status', 'user_module_status'))) {
    // Add a reference to LP status entity.
    $definition = BaseFieldDefinition::create('entity_reference')
      ->setLabel(t('Learning path status'))
      ->setDescription(t('The learning path status entity the current module attempt belongs to'))
      ->setSetting('target_type', 'user_lp_status')
      ->setSetting('target_bundles', ['user_lp_status' => 'user_lp_status']);

    $definition_update_manager->installFieldStorageDefinition('lp_status', 'user_module_status', 'opigno_module', $definition);

Here: https://git.drupalcode.org/project/opigno_learning_path/-/compare/3.0.4....

And this can only happen if I uninstall and install the module but not for cases where the module is already installed and has content in it. I add a patch that checks the same thing.

Steps to reproduce

Proposed resolution

Move the code from the hook install to a hook_update.

Remaining tasks

TBC

🐛 Bug report
Status

Needs review

Version

3.1

Component

Code

Created by

🇦🇷Argentina andreadruiz Buenos Aires

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

Comments & Activities

Production build 0.71.5 2024