Creating as a bug, maybe should be a support request, feel free to recategorize.

I have a profile which installs a custom module that provides a entity (myentity). As configuration provided by the profile (config/install/rest.settings.yml of the profile) I have:

  'entity:myentity':
    GET:
      supported_formats:
        - hal_json
      supported_auth:
        - cookie
  'entity:user':
    GET:
      supported_formats:
        - hal_json
      supported_auth:
        - cookie

On installation of this profile I get:

Original
Drupal\Component\Plugin\Exception\PluginNotFoundException: The "entity:myentity" plugin does not exist. in Drupal\Core\Plugin\DefaultPluginManager->doGetDefinition() (line 57 of /home/penyaskito/projects/wirimkiez/core/lib/Drupal/Component/Plugin/Discovery/DiscoveryTrait.php).

Drupal\Core\Plugin\DefaultPluginManager->doGetDefinition(Array, 'entity:myentity', 1)
Drupal\Core\Plugin\DefaultPluginManager->getDefinition('entity:myentity')
Drupal\Core\Plugin\Factory\ContainerFactory->createInstance('entity:myentity', Array)
Drupal\Component\Plugin\PluginManagerBase->createInstance('entity:myentity')
Drupal\rest\Plugin\Type\ResourcePluginManager->getInstance(Array)
Drupal\rest\Routing\ResourceRoutes->alterRoutes(Object)
Drupal\Core\Routing\RouteSubscriberBase->onAlterRoutes(Object, 'routing.route_alter', Object)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('routing.route_alter', Object)
Drupal\Core\Routing\RouteBuilder->rebuild()
Drupal\Core\Routing\RouteBuilder->rebuildIfNeeded()
Drupal\Core\Routing\RouteProvider->getRoutesByNames(Array)
Drupal\Core\Routing\RouteProvider->getRouteByName('')
Drupal\Core\Routing\UrlGenerator->getRoute('')
Drupal\Core\Routing\UrlGenerator->generateFromRoute('', Array, Array)
Drupal::url('')
template_preprocess_page(Array)
template_preprocess_maintenance_page(Array)
template_preprocess_install_page(Array, 'install_page', Array)
Drupal\Core\Theme\ThemeManager->theme('install_page', Array)
Drupal\Core\Theme\ThemeManager->render('install_page', Array)
Drupal\Core\Render\Renderer->doRender(Array, 1)
Drupal\Core\Render\Renderer->render(Array, 1)
Drupal\Core\Render\BareHtmlPageRenderer->renderBarePage(Array, 'Choose language', 'install_page', Array)
install_display_output(Array, Array)
install_drupal(Object)
Additional
RuntimeException: Recursive router rebuild detected. in Drupal\Core\Routing\RouteBuilder->rebuild() (line 128 of /home/penyaskito/projects/wirimkiez/core/lib/Drupal/Core/Routing/RouteBuilder.php).

Drupal\Core\Routing\RouteBuilder->rebuild()
Drupal\Core\Routing\RouteBuilder->rebuildIfNeeded()
Drupal\Core\Routing\RouteProvider->getRoutesByNames(Array)
Drupal\Core\Routing\RouteProvider->getRouteByName('')
Drupal\Core\Routing\UrlGenerator->getRoute('')
Drupal\Core\Routing\UrlGenerator->generateFromRoute('', Array, Array)
Drupal::url('')
template_preprocess_page(Array)
template_preprocess_maintenance_page(Array)
template_preprocess_install_page(Array, 'install_page', Array)
Drupal\Core\Theme\ThemeManager->theme('install_page', Array)
Drupal\Core\Theme\ThemeManager->render('install_page', Array)
Drupal\Core\Render\Renderer->doRender(Array, 1)
Drupal\Core\Render\Renderer->render(Array, 1)
Drupal\Core\Render\BareHtmlPageRenderer->renderBarePage(Array, 'Error', 'install_page', Array)
install_display_output(Array, Array)
_drupal_log_error(Array, 1)
_drupal_exception_handler(Object)

Comments

penyaskito’s picture

Status: Active » Needs review
Issue tags: +Needs tests
StatusFileSize
new899 bytes

Discussed with berdir and alexpott on IRC about the option to add config entities, but this does not really refer to entities but to plugins, so maybe is not viable.

alexpott suggested something like the fix attached. This would need tests, but not sure how we should test it.
Works perfectly for me on my usecase.

penyaskito’s picture

Component: configuration system » rest.module

REST module is probably the component that fits better with the attached patch at #1.

Status: Needs review » Needs work

The last submitted patch, 1: 2397271-1.patch, failed testing.

larowlan’s picture

Status: Needs work » Needs review
StatusFileSize
new891 bytes
new899 bytes

Working on fails

Alumei’s picture

I think this only hides the problem as the configuration states that it should be enabled but we silently ignore it because the plugin is not found.

I think config entities for endpoint configuration would enable the usage of optional configuration. Such config entity could have a dependency on the module that provides the entity type. In that case it should be installed during the installation of that module.
This should also make it possible to remove the implicit dependency of rest.settings on the node module if such a config entity would be provide for a node rest endpoint.

Alumei’s picture

I just finished the last bit of work on #2308745-106: Remove rest.settings.yml, use rest_resource config entities, which should resolve this issue as well.

Feel free to take a look ;-)

MattA’s picture

Title: REST configuration fails while installing a profile providing REST config for an entity not in core. » REST configuration fails if it contains a plugin reference that does not exist

This does not just occur during profile install. It also occurs in the following scenario:
- A contrib module with a REST plugin is installed.
- The endpoint is enabled, likely using the RestUI module.
- The contrib module is uninstalled.
- If caches are now flushed, routes are rebuilt, and the exception occurs.

Also going to update the title as this is really about plugins/plugin derivatives created for entities (and doesn't really have anything to do with entities themselves).

klausi’s picture

Status: Needs review » Needs work
+++ b/core/modules/rest/src/Routing/ResourceRoutes.php
@@ -67,8 +67,8 @@ public function __construct(ResourcePluginManager $manager, ConfigFactoryInterfa
+    $resources = $this->config->get('rest.settings')->get('resources') ?: array();
+    $enabled_resources = array_intersect_key($resources, $this->manager->getDefinitions());

So this should have a comment like "Silently ignore resources that are in the settings but are not defined on the plugin manager currently. That avoids exceptions when REST module is enabled before another module that provides the resource plugin specified in the settings."

A test case should cover this scenario of enabling REST module before node module.

wim leers’s picture

AFAICT #2308745: Remove rest.settings.yml, use rest_resource config entities would solve this on a more fundamental level. So, it's better. OTOH, it's also going to take some time until it's fixed.

So, I propose to do this now, and incorporate the proposed comment of #9, but also include a

@todo Remove in https://www.drupal.org/node/2308745.
wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new1.25 KB
new1.21 KB
wim leers’s picture

StatusFileSize
new1.38 KB
new2.4 KB

The test-only patch is also the interdiff.

The last submitted patch, 12: rest_resources-2397271-12-test-only-FAIL.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 12: rest_resources-2397271-12.patch, failed testing.

dawehner’s picture

Looks pretty good for itself. There is just this damn test failure.

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new1.35 KB
new2.57 KB

Patch doesn't apply. Because I didn't do it on latest 8.1. Silly me.

Rebased. Identical to what I posted in #12, just rebased.

wim leers’s picture

Issue tags: -Needs tests
dawehner’s picture

Status: Needs review » Reviewed & tested by the community

There we go.

The last submitted patch, 16: rest_resources-2397271-12-test-only-FAIL.patch, failed testing.

wim leers’s picture

Priority: Normal » Major
Related issues: +#2609152: Rest plugins can cause fatal's during route rebuild

Marked #2609152: Rest plugins can cause fatal's during route rebuild as a duplicate. That was major, bumping this to major.

wim leers’s picture

MattA’s picture

Just wanted to note that #2609152 also contained a bit of code to try and partially solve the underlying problem instead of just masking it like this. Theoretically, it is possible for invalid references to accumulate in rest.settings right now, which may or may not be a problem down the road.

wim leers’s picture

But it did not *really* solve anything. Only #2308745: Remove rest.settings.yml, use rest_resource config entities can really solve this entire problem.

MattA’s picture

Yep. The same can be said about this patch though. It's really a question of how far we are willing to go to minimize the problem right now before that one lands. The most important part is probably the fatal error though, so I'm fine with either solution. Just wanted to note it so that all the relevant information is available before a decision is made. :)

wim leers’s picture

@MattA++ :)

catch’s picture

Status: Reviewed & tested by the community » Needs review
+++ b/core/modules/rest/src/Routing/ResourceRoutes.php
@@ -64,7 +64,14 @@ public function __construct(ResourcePluginManager $manager, ConfigFactoryInterfa
+    // Silently ignore resources that are in the settings but are not defined on

What about a trigger_error() there to at least inform people there's an issue if things go out of sync?

wim leers’s picture

StatusFileSize
new2.72 KB
new927 bytes

There you go.

dawehner’s picture

What about listing which ones actually are missing/problematic ?

wim leers’s picture

StatusFileSize
new2.81 KB
new991 bytes

Done.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Thank you

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

A nice solution to solve the current problems until we can do #2308745: Remove rest.settings.yml, use rest_resource config entities.

Committed e9cafdf and pushed to 8.0.x and 8.1.x. Thanks!

  • alexpott committed e3da828 on 8.1.x
    Issue #2397271 by Wim Leers, larowlan, penyaskito, MattA: REST...

  • alexpott committed e9cafdf on 8.0.x
    Issue #2397271 by Wim Leers, larowlan, penyaskito, MattA: REST...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.