Problem/Motivation

Exported configuration for node types does not get imported, resulting in index not being generated

Steps to reproduce

Upgraded from 2.x, exported configuration, but on deployment no sitemap gets generated, I have to manually configure settings on each node type then manually regerate the sitemap.

Proposed resolution

configuration gets properly imported.

Comments

realityloop created an issue. See original summary.

gbyte’s picture

Title: Configuration export does not get imported correctly » Update from 2.x: Export does not get imported
gbyte’s picture

Version: 4.0.0-alpha2 » 4.x-dev
Category: Bug report » Support request

During a test direct upgrade from 2.x to 4.x I did indeed have a problem that I just fixed here: #3238398: Direct update path 2.x -> 4.x not working.

Apart from the issue above, in all my test runs I had all my settings correctly migrated to 4.x.

Are you sure you updated the database by running drush updb or visiting /update.php and then exported the configuration? The database needs to be updated on production as well and then the above configuration imported.

Would you mind trying to reproduce this issue with 4.x?

realityloop’s picture

@gbyte No, this doesn't seem to be working for me still, after config import the node settings for Simple XML Sitemap are set to do not index for some reason. (see attached image).
Setting

And here is the content of the related config export:
simple_sitemap.bundle_settings.default.node.page.yml

index: true
priority: '0.5'
changefreq: ''
include_images: false

realityloop’s picture

Some further digging it seems the Simple XML Sitemap entity bundle settings aren't getting imported on the config import tyhat occurs during deployment.

cli-drupal:/app$ drush cim -y
+------------+---------------------------------------------+-----------+
| Collection | Config                                      | Operation |
+------------+---------------------------------------------+-----------+
|            | geocoder.geocoder_provider.random           | Create    |
|            | geocoder.geocoder_provider.file             | Create    |
|            | geocoder.geocoder_provider.gpxfile          | Create    |
|            | simple_sitemap.type.default_hreflang        | Create    |
|            | reroute_email.settings                      | Create    |
|            | seckit.settings                             | Create    |
|            | simple_sitemap.sitemap.default              | Create    |
|            | core.extension                              | Update    |
|            | elasticsearch_connector.cluster.domain | Update    |
|            | simple_sitemap.settings                     | Update    |
|            | mailsystem.settings                         | Update    |
|            | simple_sitemap.sitemap.default              | Delete    |
|            | simple_sitemap.type.default_hreflang        | Delete    |
|            | geocoder.geocoder_provider.gpxfile          | Delete    |
|            | geocoder.geocoder_provider.file             | Delete    |
|            | geocoder.geocoder_provider.random           | Delete    |
|            | simple_sitemap.custom_links.default         | Delete    |
+------------+---------------------------------------------+-----------+

 // Import the listed configuration changes?: yes.         

 [notice] Synchronized extensions: install config_inspector.
 [notice] Synchronized extensions: install devel.
 [notice] Synchronized extensions: install seckit.
 [notice] Synchronized extensions: install dblog.
 [notice] Synchronized configuration: delete simple_sitemap.sitemap.default.
 [notice] Synchronized configuration: delete simple_sitemap.type.default_hreflang.
 [notice] Synchronized configuration: delete geocoder.geocoder_provider.gpxfile.
 [notice] Synchronized configuration: delete geocoder.geocoder_provider.file.
 [notice] Synchronized configuration: delete geocoder.geocoder_provider.random.
 [notice] Synchronized configuration: delete simple_sitemap.custom_links.default.
 [notice] Synchronized configuration: create geocoder.geocoder_provider.random.
 [notice] Synchronized configuration: create geocoder.geocoder_provider.file.
 [notice] Synchronized configuration: create geocoder.geocoder_provider.gpxfile.
 [notice] Synchronized configuration: create simple_sitemap.type.default_hreflang.
 [notice] Synchronized configuration: create reroute_email.settings.
 [notice] Synchronized configuration: create simple_sitemap.sitemap.default.
 [notice] Synchronized configuration: update elasticsearch_connector.cluster.domain.
 [notice] Synchronized configuration: update simple_sitemap.settings.
 [notice] Synchronized configuration: update mailsystem.settings.
 [notice] Finalizing configuration synchronization.
 [success] The configuration was imported successfully.

If I then run cim again without any changes (not really practical to do in a deployment), they do import:

cli-drupal:/app$ drush cim -y
+------------+------------------------------------------------------+-----------+
| Collection | Config                                               | Operation |
+------------+------------------------------------------------------+-----------+
|            | simple_sitemap.bundle_settings.default.node.location | Create    |
|            | simple_sitemap.bundle_settings.default.node.news     | Create    |
|            | simple_sitemap.bundle_settings.default.node.page     | Create    |
+------------+------------------------------------------------------+-----------+

 // Import the listed configuration changes?: yes. 

 [notice] Synchronized configuration: create simple_sitemap.bundle_settings.default.node.location.
 [notice] Synchronized configuration: create simple_sitemap.bundle_settings.default.node.news.
 [notice] Synchronized configuration: create simple_sitemap.bundle_settings.default.node.page.
 [notice] Finalizing configuration synchronization.
 [success] The configuration was imported successfully.
nuuou’s picture

Priority: Normal » Major

I'm seeing the exact same issue noted in #5. We're upgrading sites from 3.x and experiencing this as well.
Right now to get around it, I'm simply running "drush cim" twice in sequence, which seems to fix it on deployments.

Increasing the priority of this to "Major", as this results in lost configuration data if the developer is unaware of this.

abdhomsi’s picture

+1

gbyte’s picture

Priority: Major » Normal

I couldn't reproduce it nor do I see any suggestions in this thread on how to fix this behavior.

You guys may be running into #3241439: Config import sometimes needs be run several times to fully sync. Please go through that issue and the attached links and tell me if you think you are experiencing that core bug. Apparently many deployment scripts (not the official one though) suggest running drush cim twice.

gbyte’s picture

Category: Support request » Bug report
Status: Active » Postponed (maintainer needs more info)
weseze’s picture

Status: Postponed (maintainer needs more info) » Needs work

Ran into this issue during our update from 3.x to 4.x.

Running the update locally works perfectly fine: (simplified commands)
> drush updb -y && drush cex -y

Then commit to GIT and deploy to our staging environment: (again simplified commands)
> drush updb -y && drush cim -y && drush cr && drush deploy:hook -y
(could also use drush deploy since that does the same thing)
This runs fine, but the actual problem is hidden.

Running drush updb migates all config files (OK)

Running drush cim causes the simple_sitemap configs to be deleted and reimported because the staging environment updb will have created different uuids. The bundle_settings are now not imported because config-import has detected no changes for these files...

So now we are in the broken state.
The main culprit is "simple_sitemap_update_8216()" which can only be run on the active database, it doesn't work in a deployment workflow.

The solution to simply rerun a config-import will actually fix the issue, but does not solve the root cause of the "simple_sitemap_update_8216()" not being "deployable"...

I can see 2 possible solutions for this issue:

1/ Define dependencies within the config files so deleting and recreating config files should be picked up by the config system. (not sure about this one)

2/ Use a deploy hook to fix the broken state after config import: (I'm now using this approach to correctly deploy our updates)

function simple_sitemap_deploy_8216(&$sandbox) {
  /** @var \Drupal\Core\Site\Settings $settings */
  $settings = Drupal::service('settings');
  $files = scandir($settings->get('config_sync_directory'));
  foreach ($files as $file) {
    if (stristr($file, 'simple_sitemap.bundle_settings.')) {
      $data = \Symfony\Component\Yaml\Yaml::parse(file_get_contents($settings->get('config_sync_directory') . '/' . $file));
      $config_name = str_replace('.yml', '', $file);
      $config = \Drupal::configFactory()->getEditable($config_name);
      $config->setData($data)->save();
    }
  }
}
gbyte’s picture

@weseze

The main culprit is "simple_sitemap_update_8216()" which can only be run on the active database, it doesn't work in a deployment workflow.

Thanks for your input but what makes simple_sitemap_update_8216() different from other update hooks which use the database and read configuration and what would be the clean way to reimplement this hook in your opinion (other than the workaround you suggested)? Also feel free to create a patch.

weseze’s picture

@gbyte:

First of, it wasn't "simple_sitemap_update_8216", but "simple_sitemap_update_8403"...
I haven't looked at all update hooks, there might be others that cause similar issues. This one was simply the only that caused issues for us.

The basic issue is with creating new configs on update hooks that have some sort of logic or dependant config.
In this case the config files "simple_sitemap.bundle_settings.*.*" are actually somehow dependant on the sitemap configs. I don't know how exactly since I don't have a technical understanding of this module.

The clean way to fix this should be to define config dependencies. I tried doing that directly in the config files and then importing but I was then caught in a hell of dependency chains which I didn't understand. Again, because I don't really now how simple_sitemap works technically...

So for example, in our use case, "simple_sitemap.bundle_settings.default.node.page.yml" contains:

langcode: nl
index: true
priority: '0.5'
changefreq: ''
include_images: false

It should contain 2 extra things:
1/ A unique uuid (not sure why this is missing?)
2/ A config dependency to the sitemap configs/entities that use the page content-type. (but I don't know what that would be or how it can be added in the modules logic)

That should in theory allow a deployment workflow to correctly import everything in one go.

The deploy hook I posted previously will also fix the issue and is a much easier solution to the problem ;) Albeit somewhat dirty.

weseze’s picture

Status: Needs work » Needs review
StatusFileSize
new1.12 KB

So, our QA team detected a much bigger issues after the upgrade from 3.x to 4.x. Al of our simple_sitemap_entity_overrides were gone after deployment to QA environment.

So I did some more digging to better understand what all the update hooks, specifically 8403 was actually doing. And to understand what went wrong in a deployment that didn't go wrong when developing the update locally.

The short answer: you should not do config updates in update hooks because they can cause issues in deployments. @see: https://www.drupal.org/project/drupal/issues/3230144#comment-14202410

The long answer: you can get away with most of them and you can fix the issues that it will cause in a deployment in post_update hooks.
The main issue to be fixed here is that new configs are created and old ones deleted through an update hook. This causes different uuids on different environments and a config:import will delete/create, causing complete data loss of any "simple_sitemap_entity_overrides".

Patch attached fixes this by resetting the uuids if they exist in the active sync dir.
This can only be done in a post_update hook.

UPDATE: this should have no effect on existing installs

adamzimmermann’s picture

Status: Needs review » Reviewed & tested by the community

Updating to the 4.x version of this module was something I had shelved as I couldn't get our CI tests to pass and solving this just wasn't a priority at the moment.

During our CI process, we do the usual drush deploy steps, but then run drush config:status at the end to ensure that database config matches the tracked configuration. This config check is where things were failing, in additional to seeing issues similar to what was reported in some of the comments above.

After applying this patch our CI process completed without issue and the sitemap is still rendering as expected in the CI preview environment.

I didn't test every detail, but the latest patch solved my immediate issue and things seem to be working as expected afterwards.

Steps:

  1. drush cim -y (start with a clean config state)
  2. Add patch to composer.json file.
  3. composer require drupal/simple_sitemap:^4.0
  4. composer update --lock
  5. drush updb -y
  6. drush cex -y
  7. commit, push, etc
gbyte’s picture

Status: Reviewed & tested by the community » Needs review

@weseze

The short answer: you should not do config updates in update hooks because they can cause issues in deployments.

So what's the recommended way of doing them?

I'd appreciate one more pair of eyes before committing, preferably someone else who's had the same problem.

weseze’s picture

@gbyte: there is no easy answer to that question unfortunately... You can read through https://www.drupal.org/project/drupal/issues/3230144 and the materials referenced there to get a better understanding of what is possible in update hooks and what not and how to possibly fix those issues.

jjcarrion’s picture

I faced the same problem, after updating, all the simple_sitemap config was deleted, so no content types were set up and the sitemap was empty.

Applying patch #13 the config is still there during the deploy process and everything is working again.

  • gbyte committed 5108f54 on 4.x
    Issue #3236623 by weseze, realityloop, gbyte: Update from 2.x: Export...
gbyte’s picture

Status: Needs review » Fixed

Cleaned it up a bit and prevented warnings when configuration does not match database state. Thanks all.

Status: Fixed » Closed (fixed)

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

gbyte’s picture

Title: Update from 2.x: Export does not get imported » Update from 2.x or 3.x: Export does not get imported
loopy1492’s picture

We were getting this during ci, so we didn't really have a workaround. Thanks for the patch. Looking forward to the next release.

gbyte’s picture

@loopy1492 The next release already happened.

loopy1492’s picture

Gosh, sorry @gbyte. So it did. Thanks.