SqlContentEntityStorageSchema::getDedicatedTableSchema assumes that a fields property definitions matches the columns

Created on 6 June 2016, about 9 years ago
Updated 30 January 2023, over 2 years ago

Steps to reproduce

  1. Create a custom entity
  2. Install the custom entity
  3. Add a map field (in baseFieldDefinitions) to the above entity
  4. Try to install the new entity using an update hook

Thrown error:
Fatal error: Call to a member function isRequired() on a non-object in /var/www/html/.../core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php on line 1819

Call Stack:

  • 0.0001 223840 1. {main}() /usr/local/bin/drupal:0
  • 0.0148 1917048 2. require('phar:///usr/local/bin/drupal/bin/drupal') /usr/local/bin/drupal:10
  • 0.0150 1943328 3. require('phar:///usr/local/bin/drupal/bin/drupal.php') phar:///usr/local/bin/drupal/bin/drupal:3
  • 0.2460 7191848 4. Symfony\Component\Console\Application->run() phar:///usr/local/bin/drupal/bin/drupal.php:97
  • 0.2485 7530088 5. Drupal\Console\Application->doRun() phar:///usr/local/bin/drupal/vendor/symfony/console/Application.php:123
  • 0.8564 36435096 6. Symfony\Component\Console\Application->doRun() phar:///usr/local/bin/drupal/src/Application.php:280
  • 0.8565 36435880 7. Symfony\Component\Console\Application->doRunCommand() phar:///usr/local/bin/drupal/vendor/symfony/console/Application.php:192
  • 0.8603 36478536 8. Symfony\Component\Console\Command\Command->run() phar:///usr/local/bin/drupal/vendor/symfony/console/Application.php:860
  • 0.8605 36480536 9. Drupal\Console\Command\Update\EntitiesCommand->execute() phar:///usr/local/bin/drupal/vendor/symfony/console/Command/Command.php:259
  • 0.8686 36846752 10. Drupal\Core\Entity\EntityDefinitionUpdateManager->applyUpdates() phar:///usr/local/bin/drupal/src/Command/Update/EntitiesCommand.php:47
  • 2.6319 69601832 11. Drupal\Core\Entity\EntityDefinitionUpdateManager->doEntityUpdate() /var/www/html/.../core/lib/Drupal/Core/Entity/EntityDefinitionUpdateManager.php:105
  • 2.6319 69601832 12. Drupal\Core\Entity\EntityManager->onEntityTypeCreate() /var/www/html/.../core/lib/Drupal/Core/Entity/EntityDefinitionUpdateManager.php:210
  • 2.6319 69601832 13. Drupal\Core\Entity\EntityTypeListener->onEntityTypeCreate() /var/www/html/.../core/lib/Drupal/Core/Entity/EntityManager.php:382
  • 2.6320 69602432 14. Drupal\Core\Entity\Sql\SqlContentEntityStorage->onEntityTypeCreate() /var/www/html/.../core/lib/Drupal/Core/Entity/EntityTypeListener.php:71
  • 2.6320 69603168 15. Drupal\Core\Entity\Sql\SqlContentEntityStorage->wrapSchemaException() /var/www/html/.../core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php:1357
  • 2.6320 69603336 16. Drupal\Core\Entity\Sql\SqlContentEntityStorage->Drupal\Core\Entity\Sql\{closure}() /var/www/html/.../core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php:1452
  • 2.6364 69715576 17. Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema->onEntityTypeCreate() /var/www/html/.../core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php:1356
  • 2.6811 70216352 18. Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema->createDedicatedTableSchema() /var/www/html/.../core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php:276
  • 2.6811 70216352 19. Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema->getDedicatedTableSchema() /var/www/html/.../core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php:1102
🐛 Bug report
Status

Needs work

Version

9.5

Component
Field 

Last updated 23 minutes ago

Created by

🇮🇱Israel Eyal Shalev

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

Comments & Activities

Not all content is available!

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

  • The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

  • Status changed to Postponed: needs info about 2 hours ago
  • 🇦🇺Australia acbramley

    Tried to reproduce this on HEAD using a base field on Node:

    1. Install standard
    2. Add the following to node.post_update.php:

    function node_post_update_foo(): void {
      $field_definition = BaseFieldDefinition::create('map')
        ->setLabel(t('Foo'))
        ->setRequired(TRUE)
        ->setDisplayConfigurable('form', FALSE)
        ->setDisplayConfigurable('view', FALSE);
      $definition_update_manager = \Drupal::entityDefinitionUpdateManager();
      $definition_update_manager->installFieldStorageDefinition('foo', 'node', 'node', $field_definition);
    }
    

    3. Add the following to Node::baseFieldDefinitions:

        $fields['foo'] = BaseFieldDefinition::create('map')
          ->setLabel(t('Foo'))
          ->setRequired(TRUE)
          ->setDisplayConfigurable('form', FALSE)
          ->setDisplayConfigurable('view', FALSE);
    

    4. Run drush updb -y

    No errors, the field is added to the node_field_data table

    5. Try the opposite:

    function node_post_update_bar(): void {
      $definition_update_manager = \Drupal::entityDefinitionUpdateManager();
      if ($field_definition = $definition_update_manager->getFieldStorageDefinition('foo', 'node')) {
        $definition_update_manager->uninstallFieldStorageDefinition($field_definition);
      }
    }
    

    No errors, the field is removed from the node_field_data table.

    Has this been fixed elsewhere?

Production build 0.71.5 2024