Problem/Motivation

After upgrading to sitemap-8.x-2.0-beta7 and running drush updb followed by drush config:import, then going to /admin/config/search/sitemap results in the following error:

Symfony\Component\Routing\Exception\RouteNotFoundException: Route "sitemap.page" does not exist. in Drupal\Core\Routing\RouteProvider->getRouteByName() (line 206 of core/lib/Drupal/Core/Routing/RouteProvider.php). 

Drupal\Core\Routing\UrlGenerator->getRoute('sitemap.page') (Line: 276)
Drupal\Core\Routing\UrlGenerator->generateFromRoute('sitemap.page', Array, Array, 1) (Line: 108)
Drupal\Core\Render\MetadataBubblingUrlGenerator->generateFromRoute('sitemap.page', Array, Array, 1) (Line: 765)
Drupal\Core\Url->toString(1) (Line: 183)
Drupal\Core\Utility\LinkGenerator->generate(Object, Object) (Line: 164)
Drupal\Core\Link->toString() (Line: 81)
Drupal\sitemap\Form\SitemapSettingsForm->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 536)
Drupal\Core\Form\FormBuilder->retrieveForm('sitemap_settings', Object) (Line: 283)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 627)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 121)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Steps to reproduce

  1. Download Drupal core: composer create drupal/recommended-project:10.2.7
  2. Download Drush: composer require drush/drush
  3. Download sitemap-8.x-2.0-beta6 composer require drupal/sitemap:2.0.0-beta6
  4. Install Drupal with the minimal install profile: drush site:install -y minimal
  5. Install Sitemap: drush -y pm:install sitemap
  6. Login: drush -y uli
  7. Export configuration: drush -y config:export
  8. Go to /admin/config/search/sitemap to confirm you see the page
  9. Upgrade sitemap to sitemap-8.x-2.0-beta7: ddev composer require drupal/sitemap:2.0.0-beta7
  10. Run database updates and import config (either drush -y deploy or drush -y updb followed by drush -y config:import)
  11. Go to /admin/config/search/sitemap
    • Expected behavior: you see the config page you saw in step 8
    • Actual behavior: You see a RouteNotFoundException: Route "sitemap.page" does not exist error.

Proposed resolution

This happens because the changes in #3348769: Customize the sitemap path introduces new configuration. This new configuration is set to a default value in the sitemap_update_8201() database update hook.

In beta7 and beta8, the production code needs that configuration in place in order to create the sitemap.page route where the sitemap is displayed.

However, if drush deploy is run, or drush updatedb is run and drush config:import is run immediately afterwards, then the new configuration-import step deletes the new configuration. When Drupal goes to create the sitemap.page route later, then the configuration is missing, and the route is not created. The reason why this error shows up on the sitemap configuration page (i.e.: sitemap.settings) is because the link to the sitemap is displayed as a "View" link in the menu tasks (i.e.: as a tab at the top of the page).

Remaining tasks

  1. Determine steps to reproduce
  2. Write a patch
  3. Review and feedback - skipped because the maintainer wrote the patch
  4. RTBC and feedback
  5. Commit
  6. Release

User interface changes

None.

API changes

None.

Data model changes

None.

Issue fork sitemap-3466939

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

shelane created an issue. See original summary.

dcam’s picture

This happened to me after I updated the module, but I hadn't run the database updates. Did you?

shelane’s picture

Yes, I run updates as part of the deployment. I have cleared the cache as well.

mparker17’s picture

By any chance, are you running database updates and then importing config right afterwards (e.g.: like drush deploy)?

The sitemap.page route used to be defined in sitemap.routing.yml, but in #3348769: Customize the sitemap path we changed it to be defined by \Drupal\sitemap\EventSubscriber\RouteSubscriber::alterRoutes() so the path can be stored in a new configuration key (see commit ea3e82fa).

(3348769 was merged back in April, but apparently didn't get released until now — apologies!)

The sitemap_update_8201() update hook sets the new configuration key to be sitemap (i.e.: /sitemap), but if you import the old configuration right after running database updates, it is possible that the newly-added configuration gets deleted by the config-import that gets run right afterwards.

(note, we also set the default to sitemap in config/install/sitemap.settings.yml, but that is only used when the module is installed)

As a work-around you might want to...

  1. Update sitemap locally
  2. Run drush updatedb or update.php
  3. Run drush config:export or export config from the UI
  4. Commit the change to sitemap.settings.yml

... I will add this work-around to the module release notes right away.


In the mean time, does anyone know of a more-permanent way to solve this, or could point me to what another project (e.g.: core, contrib) has done?

The only thing I can think of right now is exporting configuration in the update hook, but I don't think that is a recommended practice, especially for sites that have their production filesystem set to read-only (e.g.: Pantheon).


I do a lot of manual testing, but I don't think that I ran into this locally, because I had previously run into this problem back in 2019 on other modules, so I had gotten into the habit of...

  1. updating modules locally,
  2. running database updates,
  3. exporting config,
  4. committing the changes, and
  5. pushing that to my shared environments, which then run drush deploy (i.e.: on the updated, newly-exported config)

... but I'll bet that not everyone does this.

shelane’s picture

Those are the steps I ran locally when I updated them module. There was no new config exported after I ran the updates and config exports for sitemap. Since it has already been updated, and updated locally and the admin config page to set a path is inaccessible, I'm not sure what the local steps to fix are.

mparker17’s picture

@shelane, if you have drush, could you try running drush config:set sitemap.settings path 'sitemap', and let me know if that fixes the problem? If so, I will add that to the release notes as well.

shelane’s picture

I ran that step which did add path: sitemap to the sitemap config. However, that did not fix the error trying to go to the admin configuration page.

mparker17’s picture

I apologize for the delay replying... I appear to be the only active maintainer of this module, and it took me a while to wrap my head around the chicken-and-egg nature of the problem.

As mentioned earlier, if you update the module, run database updates, export config, and commit that, then everything works fine going forward. But if it didn't happen exactly that way after upgrading, then your site gets into a state where it can't build the new route because it can't find the config, so clearing caches doesn't help.

I have some code that appears to make it work on my test environment, and I'll add an update hook to rebuild the router cache as well.

I will post a merge request and patch shortly, if you could test it and tell me if it works, then I can create a new release.

Thank you again for your patience.

mparker17’s picture

Status: Active » Needs review
StatusFileSize
new1.58 KB

@shelane, may I trouble you to try the attached patch and let me know if it fixes the problem?

EDIT: actually... look for a new patch below. This particular patch — 3466939-9--route-does-not-exist-error-after-beta7.patch — might not apply due to the change added in #3465577: Split sitemap_book config schema from sitemap schema. I will have to craft a new patch for you, but that's non-trivial because I don't want your local to skip the change from 3465577 when that is actually applied. (apologies, being a module-maintainer is rather complicated, thank you for your patience)


How to apply the patch with composer:

  1. Add the URL of the patch file to the composer.json file in the extra -> patches section:
        {
            ...
            "extra": {
                ...
                "patches": {
                  ...
                  "drupal/sitemap": {
                      "3466939-9: ": "https://www.drupal.org/files/issues/2024-08-12/3466939-9--route-does-not-exist-error-after-beta7.patch"
                  }
                  ...
                },
                ...
            }
            ...
        }
      
  2. Run composer update drupal/sitemap to update the lock file.
  3. Verify that line 39 in .../modules/.../sitemap/src/EventSubscriber/RouteSubscriber.php looks like $path = $this->config->get('path') ?? 'sitemap';
  4. Run database updates
  5. Log in if you aren't already
  6. Visit /admin/config/search/sitemap: the config page should load without errors. Please let me know what happens by adding a comment in this issue.
  7. If this works, then:
    1. Click the Save configuration button at the bottom of the page.
    2. Export configuration. You should see a change to sitemap.settings.yml that adds the line path: sitemap.
    3. Commit the change to sitemap.settings.yml.
    4. At this point, the un-patched code should work again, so in preparation for upgrading to beta9:
      1. Undo the change to composer.json in the extra -> patches section that you made in step 1
      2. Run composer update drupal/sitemap to update the lock file.
      3. Double-check that the config page loads without errors by going to /admin/config/search/sitemap.

I will update the issue summary shortly.

mparker17’s picture

Title: Attempt to go to config page for sitemap results in WSOD » Route "sitemap.page" does not exist error after upgrading to 8.x-2.0-beta7
Version: 8.x-2.0-beta8 » 8.x-2.x-dev
Issue summary: View changes
Priority: Normal » Major

Updating issue title to better summarize the problem.

Moving to "Major" priority as per Issue Priority field documentation for Major Bugs ("Trigger[s] a PHP error through the user interface, but only under rare circumstances or affecting only a small percentage of all users, even if there is a workaround.")

Updated issue summary, part 1.

mparker17’s picture

Issue summary: View changes

Updated issue summary, part 2: added steps to reproduce.

mparker17’s picture

Status: Needs review » Reviewed & tested by the community

After some work, I'm not really sure that there is a way for me to make a patch to test that (a) doesn't contain unrelated changes, and (b) that running database updates from won't break the module in the future (due to the very important config changes made in an update hook in the previous patch).

However, I've tested this several different ways on several different sites at this point, so I feel like it is ready to merge and make a new release, so I'm going to do that shortly.

(although this time I'm going to make clear that there are database hooks which modify configuration — and what to do about that)

I am crediting @dcam on this issue, for their excellent update hook test, which I've made use of here.

  • mparker17 committed 47a20c2f on 8.x-2.x
    Issue #3466939 by shelane, mparker17, dcam: Route "sitemap.page" does...
mparker17’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Fixed

This has been merged, and I'm getting ready to make a release.

mparker17’s picture

Issue summary: View changes

This fix has been released in sitemap-8.x-2.0-beta9.

Status: Fixed » Closed (fixed)

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