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
- Download Drupal core:
composer create drupal/recommended-project:10.2.7 - Download Drush:
composer require drush/drush - Download sitemap-8.x-2.0-beta6
composer require drupal/sitemap:2.0.0-beta6 - Install Drupal with the minimal install profile:
drush site:install -y minimal - Install Sitemap:
drush -y pm:install sitemap - Login:
drush -y uli - Export configuration:
drush -y config:export - Go to
/admin/config/search/sitemapto confirm you see the page - Upgrade sitemap to sitemap-8.x-2.0-beta7:
ddev composer require drupal/sitemap:2.0.0-beta7 - Run database updates and import config (either
drush -y deployordrush -y updbfollowed bydrush -y config:import) - 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
Determine steps to reproduceWrite a patchReview and feedback- skipped because the maintainer wrote the patchRTBC and feedbackCommitRelease
User interface changes
None.
API changes
None.
Data model changes
None.
| Comment | File | Size | Author |
|---|
Issue fork sitemap-3466939
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
Comment #2
dcam commentedThis happened to me after I updated the module, but I hadn't run the database updates. Did you?
Comment #3
shelaneYes, I run updates as part of the deployment. I have cleared the cache as well.
Comment #4
mparker17By any chance, are you running database updates and then importing config right afterwards (e.g.: like drush deploy)?
The
sitemap.pageroute used to be defined insitemap.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 besitemap(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
sitemapinconfig/install/sitemap.settings.yml, but that is only used when the module is installed)As a work-around you might want to...
drush updatedbor update.phpdrush config:exportor export config from the UIsitemap.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...
drush deploy(i.e.: on the updated, newly-exported config)... but I'll bet that not everyone does this.
Comment #5
shelaneThose 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.
Comment #6
mparker17@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.Comment #7
shelaneI ran that step which did add
path: sitemapto the sitemap config. However, that did not fix the error trying to go to the admin configuration page.Comment #8
mparker17I 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.
Comment #9
mparker17@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:
composer.jsonfile in theextra->patchessection:composer update drupal/sitemapto update the lock file..../modules/.../sitemap/src/EventSubscriber/RouteSubscriber.phplooks like$path = $this->config->get('path') ?? 'sitemap';/admin/config/search/sitemap: the config page should load without errors. Please let me know what happens by adding a comment in this issue.sitemap.settings.ymlthat adds the linepath: sitemap.sitemap.settings.yml.extra->patchessection that you made in step 1composer update drupal/sitemapto update the lock file./admin/config/search/sitemap.I will update the issue summary shortly.
Comment #10
mparker17Updating 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.
Comment #12
mparker17Updated issue summary, part 2: added steps to reproduce.
Comment #13
mparker17After 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.
Comment #15
mparker17This has been merged, and I'm getting ready to make a release.
Comment #16
mparker17This fix has been released in sitemap-8.x-2.0-beta9.