field_field_config_create should check if the config installer is syncing

Created on 15 February 2024, 7 months ago
Updated 18 March 2024, 6 months ago

Problem/Motivation

Running drush site:install --existing-config when there is a field using the Entity Reference Hierarchy reference method selection handler results in a fail with the following error:

TypeError: uasort(): Argument #1 ($array) must be of type array, null given in uasort() (line 65 of /var/www/html/docroot/core/lib/Drupal/Core/Entity/EntityReferenceSelection/SelectionPluginManager.php) #0 /var/www/html/docroot/core/lib/Drupal/Core/Entity/EntityReferenceSelection/SelectionPluginManager.php(65): uasort(NULL, Array)

This seems to happen because the deriver for the selection plugin only adds one for each entity type that already has an Entity Reference Hierarchy field. In our case, we only have one field of that type, and it uses the ERH reference type. This error may not occur if the first field to be created in config does not use the ERH selection plugin.

Steps to reproduce

  1. Build a site with this module enabled and one entity reference hierarchy field added to a content type.
  2. Change the reference type for the field to "Entity Reference Hierarchy".
  3. Export config.
  4. Run drush site-install --existing-config

Proposed resolution

Update the deriver logic, so it doesn't require an ERH field to exist before it makes the selection plugin available for an entity type.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Fixed

Version

10.2 ✨

Component
FieldΒ  β†’

Last updated 1 day ago

Created by

πŸ‡ΊπŸ‡ΈUnited States byrond

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

Merge Requests

Comments & Activities

  • Issue created by @byrond
  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    Thanks, this is a recent issue introduced by Drupal 10.2, it is even failing our tests https://git.drupalcode.org/project/entity_hierarchy/-/jobs/820556

  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    Update the deriver logic, so it doesn't require an ERH field to exist before it makes the selection plugin available for an entity type.

    These plugins will be broken though.

    Can you get a stack trace? I wonder if we need to be invalidating a selection handler plugin cache at some point instead.

  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10
  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10
  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    I think we probably want a hook_field_field_config_insert that calls ::clearCachedDefinitions on the ER select handler manager if the field-type is entity_hierarchy

  • Open on Drupal.org β†’
    Core: 10.2.1 + Environment: PHP 8.1 & MySQL 8
    last update 7 months ago
    Waiting for branch to pass
  • Status changed to Needs review 7 months ago
  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10
  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    MR fixes the issue in HEAD

    Can you confirm it resolves your install issue?

    If so I can get a new release out today.

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

    It did not fix our issue. I'm not sure the cache clear will help in this case, because it is trying to create the field, which can't succeed until a field exists to be picked up by getDerivativeDefinitions().

    Here is our stack trace:

     [error]  TypeError: uasort(): Argument #1 ($array) must be of type array, null given in uasort() (line 65 of /var/www/html/docroot/core/lib/Drupal/Core/Entity/EntityReferenceSelection/SelectionPluginManager.php) #0 /var/www/html/docroot/core/lib/Drupal/Core/Entity/EntityReferenceSelection/SelectionPluginManager.php(65): uasort(NULL, Array)
    #1 /var/www/html/docroot/core/modules/field/field.module(414): Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginManager->getPluginId('node', 'entity_hierarch...')
    #2 [internal function]: field_field_config_create(Object(Drupal\field\Entity\FieldConfig))
    #3 /var/www/html/docroot/core/lib/Drupal/Core/Extension/ModuleHandler.php(409): call_user_func_array(Object(Closure), Array)
    #4 /var/www/html/docroot/core/lib/Drupal/Core/Extension/ModuleHandler.php(388): Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}(Object(Closure), 'field')
    #5 /var/www/html/docroot/core/lib/Drupal/Core/Extension/ModuleHandler.php(408): Drupal\Core\Extension\ModuleHandler->invokeAllWith('field_config_cr...', Object(Closure))
    #6 /var/www/html/docroot/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php(341): Drupal\Core\Extension\ModuleHandler->invokeAll('field_config_cr...', Array)
    #7 /var/www/html/docroot/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php(434): Drupal\Core\Config\Entity\ConfigEntityStorage->invokeHook('create', Object(Drupal\field\Entity\FieldConfig))
    #8 /var/www/html/docroot/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php(357): Drupal\Core\Config\Entity\ConfigEntityStorage->_doCreateFromStorageRecord(Array, true)
    #9 /var/www/html/docroot/core/lib/Drupal/Core/Config/ConfigImporter.php(1059): Drupal\Core\Config\Entity\ConfigEntityStorage->importCreate('field.field.nod...', Object(Drupal\Core\Config\Config), Object(Drupal\Core\Config\Config))
    #10 /var/www/html/docroot/core/lib/Drupal/Core/Config/ConfigImporter.php(842): Drupal\Core\Config\ConfigImporter->importInvokeOwner('', 'create', 'field.field.nod...')
    #11 /var/www/html/docroot/core/lib/Drupal/Core/Config/ConfigImporter.php(663): Drupal\Core\Config\ConfigImporter->processConfiguration('', 'create', 'field.field.nod...')
    #12 /var/www/html/docroot/core/lib/Drupal/Core/Config/ConfigImporter.php(561): Drupal\Core\Config\ConfigImporter->processConfigurations(Array)
    #13 /var/www/html/docroot/core/lib/Drupal/Core/Config/Importer/ConfigImporterBatch.php(31): Drupal\Core\Config\ConfigImporter->doSyncStep('processConfigur...', Array)
    #14 /var/www/html/docroot/core/includes/batch.inc(296): Drupal\Core\Config\Importer\ConfigImporterBatch::process(Object(Drupal\Core\Config\ConfigImporter), 'processConfigur...', Array)
    #15 /var/www/html/docroot/core/includes/form.inc(974): _batch_process()
    #16 /var/www/html/docroot/core/includes/install.core.inc(660): batch_process(Object(Drupal\Core\Url), Object(Drupal\Core\Url))
    #17 /var/www/html/docroot/core/includes/install.core.inc(578): install_run_task(Array, Array)
    #18 /var/www/html/docroot/core/includes/install.core.inc(121): install_run_tasks(Array, Array)
    #19 /var/www/html/vendor/drush/drush/includes/drush.inc(69): install_drupal(Object(Composer\Autoload\ClassLoader), Array, Array)
    #20 /var/www/html/vendor/drush/drush/includes/drush.inc(53): drush_call_user_func_array('install_drupal', Array)
    #21 /var/www/html/vendor/drush/drush/src/Commands/core/SiteInstallCommands.php(169): drush_op('install_drupal', Object(Composer\Autoload\ClassLoader), Array, Array)
    #22 [internal function]: Drush\Commands\core\SiteInstallCommands->install('minimal', Array)
    #23 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(276): call_user_func_array(Array, Array)
    #24 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback(Array, Object(Consolidation\AnnotatedCommand\CommandData))
    #25 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(175): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter(Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
    #26 /var/www/html/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(387): Consolidation\AnnotatedCommand\CommandProcessor->process(Object(Symfony\Component\Console\Output\ConsoleOutput), Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
    #27 /var/www/html/vendor/symfony/console/Command/Command.php(326): Consolidation\AnnotatedCommand\AnnotatedCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
    #28 /var/www/html/vendor/symfony/console/Application.php(1096): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
    #29 /var/www/html/vendor/symfony/console/Application.php(324): Symfony\Component\Console\Application->doRunCommand(Object(Consolidation\AnnotatedCommand\AnnotatedCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
    #30 /var/www/html/vendor/symfony/console/Application.php(175): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
    #31 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(110): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
    #32 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(40): Drush\Runtime\Runtime->doRun(Array, Object(Symfony\Component\Console\Output\ConsoleOutput))
    #33 /var/www/html/vendor/drush/drush/drush.php(139): Drush\Runtime\Runtime->run(Array)
    #34 /var/www/html/vendor/drush/drush/drush(4): require('/var/www/html/v...')
    #35 /var/www/html/vendor/bin/drush(119): include('/var/www/html/v...')
    #36 {main}. 
    

    My proposal was to make sure plugin derivatives get created for every entity type, whether or not a field exists already, but I don't know enough about this module to understand why that will break things.

  • Status changed to Needs work 7 months ago
  • πŸ‡ΊπŸ‡ΈUnited States byrond
  • Pipeline finished with Skipped
    7 months ago
    #101034
    • larowlan β†’ committed 3054055b on 3.x
      Issue #3421731: drush site:install fails with entity hierarchy field in...
  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    Merging the MR because it fixes tests. Back to the drawing board

  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    but I don't know enough about this module to understand why that will break things.

    The plugin expects tables/fields etc to exist in order to query the hierarchy

  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    I actually think this is a core issue, I think `field_field_config_create` should be checking if the config manager is syncing.

  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    larowlan β†’ changed the visibility of the branch 3421731-drush-siteinstall-fails to hidden.

  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10
  • Status changed to Needs review 7 months ago
  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    Added an MR with a test

  • Status changed to RTBC 7 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Test coverage is shown here https://git.drupalcode.org/project/drupal/-/jobs/875136

    Early return if syncing makes sense and simple enough that I think marking now is fine.

  • Status changed to Fixed 6 months ago
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    Committed and pushed b32845ead7 to 11.x and 65e255676e to 10.3.x and f0738dc9ee to 10.2.x. Thanks!

    • alexpott β†’ committed f0738dc9 on 10.2.x
      Issue #3421731 by larowlan, byrond: field_field_config_create should...
    • alexpott β†’ committed 65e25567 on 10.3.x
      Issue #3421731 by larowlan, byrond: field_field_config_create should...
    • alexpott β†’ committed b32845ea on 11.x
      Issue #3421731 by larowlan, byrond: field_field_config_create should...
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024