MigrationPluginManager::createInstances claims to throw a PluginException on invalid IDs, but does not

Created on 29 September 2023, about 2 years ago
Updated 12 November 2023, almost 2 years ago

Problem/Motivation

The docblock for MigrationPluginInterface::createInstances like most plugin managers has a @throws tag:

   *
   * @throws \Drupal\Component\Plugin\Exception\PluginException
   *   If an instance cannot be created, such as if the ID is invalid.
   */

to throw an exception if invalid plugin ids are requested. This exception would typically bubble up from $factory->createInstance($plugin_id... However MigrationPluginManager runs the passed plugin ids through MigrationPluginManger::expandPluginIds() which is used to find derived plugins. The code in expandPluginIds

  /**
   * {@inheritdoc}
   */
  public function expandPluginIds(array $migration_ids) {
    $plugin_ids = [];
    $all_ids = array_keys($this->getDefinitions());
    foreach ($migration_ids as $id) {
      $plugin_ids += preg_grep('/^' . preg_quote($id, '/') . PluginBase::DERIVATIVE_SEPARATOR . '/', $all_ids);
      if ($this->hasDefinition($id)) {
        $plugin_ids[] = $id;
      }
    }
    return $plugin_ids;
  }

effectively builds a new list of plugin ids filtered through the discovered plugins, silently removing any invalid ids without trying to create them, leaving no opportunity for the exception to bubble up.

Steps to reproduce

Proposed resolution

We should have expandPluginIds throw an exception if neither the requested id or derivatives on it are found, or it should remove the original plugin id only if derivitives are found, ensuring that $factory::createInstance() has an opportunity to throw an exception on the invalid id.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

πŸ“Œ Task
Status

Needs work

Version

11.0 πŸ”₯

Component
MigrationΒ  β†’

Last updated about 1 month ago

Created by

πŸ‡ΊπŸ‡ΈUnited States mikelutz Michigan, USA

Live updates comments and jobs are added and updated live.
  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

  • Needs subsystem maintainer review

    It is used to alert the maintainer(s) of a particular core subsystem that an issue significantly impacts their subsystem, and their signoff is needed (see the governance policy draft for more information). Also, if you use this tag, make sure the issue component is set to the correct subsystem. If an issue significantly impacts more than one subsystem, use needs framework manager review instead.

Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024