LogicException: Missing bundle entity, entity type file_type, entity id undefined

Created on 30 January 2024, 10 months ago
Updated 19 September 2024, about 2 months ago

Problem/Motivation

After upgrading from Drupal 9 to Drupal 10 and updating File Entity module from 8.x-2.0-rc1 to 8.x-2.0-rc5 I receive PHP error when attempting saving page Content language and translation (/admin/config/regional/content-language):

LogicException: Missing bundle entity, entity type file_type, entity id undefined. in Drupal\Core\Entity\EntityType->getBundleConfigDependency() (line 877 of [...]/core/lib/Drupal/Core/Entity/EntityType.php).

Steps to reproduce

1. Update File Entity module from 8.x-2.0-rc1 to 8.x-2.0-rc5
2. Go to page Content language and translation (/admin/config/regional/content-language):
3. Save the page

PHP error:
LogicException: Missing bundle entity, entity type file_type, entity id undefined. in Drupal\Core\Entity\EntityType->getBundleConfigDependency() (line 877 of [...]/core/lib/Drupal/Core/Entity/EntityType.php).

Downgrading File Entity module from version 8.x-2.0-rc5 to 8.x-2.0-rc1 doesn't trigger the above error

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Component

Code

Created by

🇬🇧United Kingdom gebiss

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

Comments & Activities

  • Issue created by @gebiss
  • 🇮🇳India naushunaushad

    This is because of the 'undefined' file type from file_entity module. As a temporary fix, I added below patch for language module.

    --- a/core/modules/language/src/Entity/ContentLanguageSettings.php
    +++ b/core/modules/language/src/Entity/ContentLanguageSettings.php
    @@ -206,10 +206,12 @@
    public function calculateDependencies() {
    parent::calculateDependencies();

    - // Create dependency on the bundle.
    - $entity_type = \Drupal::entityTypeManager()->getDefinition($this->target_entity_type_id);
    - $bundle_config_dependency = $entity_type->getBundleConfigDependency($this->target_bundle);
    - $this->addDependency($bundle_config_dependency['type'], $bundle_config_dependency['name']);
    + if($this->target_bundle !== 'undefined') {
    + // Create dependency on the bundle.
    + $entity_type = \Drupal::entityTypeManager()->getDefinition($this->target_entity_type_id);
    + $bundle_config_dependency = $entity_type->getBundleConfigDependency($this->target_bundle);
    + $this->addDependency($bundle_config_dependency['type'], $bundle_config_dependency['name']);
    + }

    return $this;
    }

  • 🇮🇳India dineshkumarbollu

    +1 error in Fresh installation also 8.x-2.0-rc5, Is this related to Core?

  • 🇨🇦Canada Natkeeran

    Ran into the same issue, when trying to update the configuration !.

  • 🇨🇦Canada nikathone Ontario

    My work around was to implement a hook form alter and removed the undefined bundle from being picked up by the content language settings form.

    <?php
    /**
     * Implements hook_form_FORM_ID_alter() for language_content_settings_form.
     */
    function mycustom_module_form_language_content_settings_form_alter(array &$form, Drupal\Core\Form\FormStateInterface $form_state, string $form_id) {
      // Unset undefined bundle added by the file entity to avoid a LogicException.
      // See https://www.drupal.org/i/3417971
      if (!empty($form['settings']['file']['undefined'])) {
        unset($form['settings']['file']['undefined']);
      }
    }
    ?>

    I also think a solution should be implemented in this module because it's the one that introduced the undefined bundle. Setting this to major because it's stopping people with translation enabled to update the settings for content language.

  • 🇨🇦Canada joseph.olstad

    if someone is able to pinpoint the commit that caused this that would be helpful to know.

    rc1 to rc5 is a bit wide in scope.

  • 🇪🇸Spain bmunslow

    I was hit by this as well. I can confirm this issue was introduced in 8.x-2.0-rc5. Issue disappears after downgrading to 8.x-2.0-rc4 or previous versions.

    I compared revisions 8.x-2.0-rc5 and 8.x-2.0-rc4 and there is a single commit of difference between them, which introduced the issue.

    In short, a new hook was added in file_entity.module which defines the Undefined bundle to fix validation issues.

    As @Berdir anticipated in #3403892 📌 Set up Gitlab CI, fix tests and 10.2 compatibility Fixed , this hook fixed the 10.2 compatibility problems as a workaround, but introduced this new issue.

    Hope this helps in moving forward to fixing it.

  • 🇪🇸Spain bmunslow

    Beware that #5 will likely re-introduce the compatibility issue with Drupal 10.2 that the Undefined file entity bundle was attempting to fix.

    IMHO, #2 is preferred as a temporary fix until this issue is resolved.

  • 🇨🇭Switzerland berdir Switzerland
  • Assigned to berdir
  • 🇨🇦Canada joseph.olstad

    @berdir, check the recent comment, it was reported that one of your fairly recent commits introduced a regression.

  • 🇨🇭Switzerland berdir Switzerland

    Looks like getBundleConfigDependency() doesn't like having a mix of bundle and code defined bundles. I guess that means that undefined will need to be defined as a real config entity then with protection against deleting it.

  • 🇨🇴Colombia yasminOrj

    Hi, I tried the patch from comment #2, and it worked.

    Thanks

  • 🇨🇦Canada joel_osc

    Just adding the workaround patch from #2 as a patch file for composer to apply until a solution is found. Thank-you @naushunaushad.

  • 🇨🇦Canada joseph.olstad

    Just noticed:
    #14 is a core patch, not a patch for file_entity.

  • 🇺🇸United States j2 Utah, USA

    Patch seems to have worked!

  • The #14 (#2) core patch seems to have fixed the error in /admin/config/regional/content-language
    However, when trying to import a .po file at /admin/config/regional/translate/import I got a similar error:

    "The specified file fr.po could not be uploaded.
    The referenced entity (file_type: undefined) does not exist."

  • I had the same issue #17
    I've resolved it with the following code

    /**
     * Implements hook_file_mimetype_mapping_alter().
     */
    function module_name_file_mimetype_mapping_alter(array &$mapping) {
      // Add text/plain mimetype for .po files.
      $mapping['extensions']['po'] = 292;
    }
    

    This issue happens because Drupal can't define .po file mime-type

  • 🇨🇴Colombia yasminOrj

    I changed the status to needs review.

  • 🇨🇦Canada joseph.olstad

    ok, rather than rely on a core patch, someone should test backing off the core patch and using an approach that takes into consideration what is being reported in comment #18.

    Perhaps this is just a configuration issue? I'm not sure what the number 292 means.

  • 🇨🇭Switzerland berdir Switzerland

    Yes, this can't be needs review, there is no patch for this project. #12 explains what needs to be done, undefined needs to be defined as an explicit config entity, with update function and also entity access to prevent update/delete.

Production build 0.71.5 2024