Problem/Motivation

We noticed a problem with config_split when exporting a split containing config that is overridden : the override is exported in the YAML file.
This happens because ConfigSplitManager::splitPreview() calls ConfigManager::getConfigEntitiesToChangeOnDependencyRemoval() which then calls ConfigManager::findConfigEntityDependenciesAsEntities() and it returns config containing our override.

Steps to reproduce

Here is how we noticed it:

  • Install config_split 2.
  • Create a complete split on a specific config that has a corresponding permission (the permission must depend on the splitted configuration).
  • Force the permission in settings.php like this:
    $config['user.role.anonymous']['permissions'][9999] = 'my permission'; 
  • Run drush cex.
  • The permission is added to the export.

Proposed resolution

findConfigEntityDependenciesAsEntities() uses loadMultiple() and I think it should use loadMultipleOverrideFree() instead.
If I understand correctly, this method is used to know which config needs to be deleted or changed when deleting config or uninstalling a module. Drupal will not be able to delete or change the overrides defined in code so it does not make sense to return them here.

API changes

If findConfigEntityDependenciesAsEntities() is used by some contrib modules, we might need to add a new $loadOverrides = FALSE argument in order to not change the default behavior.

Issue fork drupal-3326900

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

prudloff created an issue. See original summary.

prudloff’s picture

Status: Active » Needs review

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative, +Needs tests

This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

As a bug this will need a test case

prudloff’s picture

prudloff’s picture

We also encountered this problem while uninstalling a module. Drupal loads the overridden config when trying to remove the permission that depend on this module from roles.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

gaëlg’s picture

prudloff’s picture

Status: Closed (duplicate) » Needs work

Reopening because as discussed in #2910353: Prevent saving config entities when configuration overrides are applied it will be easier to fix these problems in separate small patches and keep 2910353 only about triggering an exception when saving overridden config.

prudloff’s picture

Version: 11.x-dev » main

prudloff changed the visibility of the branch main to hidden.

berdir’s picture

Thanks for splitting/reopening. I think we should clarify with a core committer whether or not these issues require explicit test coverage. The change is pretty obvious, in the long-term plan in the related issue is to deprecate and eventually disallow using loadMultiple() followed by a save() call. Adding a test for every scenario that we're updating is going to result in a lot of extra tests that we have to write and maintain.

alexpott’s picture

I think in this case a test would be a good thing because the method is not loading and saving the entities itself. The entities it loads and returns are part of its API.

The fix looks good though and I'd be very happy to see this land. +1 on splitting out the issues too.

prudloff’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests

I added a test that fails without the patch.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

This one already seemed to get sign off. Test coverage is there https://git.drupalcode.org/issue/drupal-3326900/-/jobs/8925511

Don't see any outstanding threads and have no additional feedback so will mark.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

I think we should document that the configuration entities are loaded override free in \Drupal\Core\Config\ConfigManagerInterface::findConfigEntityDependenciesAsEntities()

prudloff’s picture

Status: Needs work » Needs review

I added a comment on the interface about config being loaded without overrides.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Feedback appears to be addressed.

alexpott’s picture

Version: main » 11.x-dev
Status: Reviewed & tested by the community » Fixed

Committed and pushed c7a864dce30 to main and dcebf583e6c to 11.x. Thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • alexpott committed dcebf583 on 11.x
    task: #3326900 ConfigManager::findConfigEntityDependenciesAsEntities()...

  • alexpott committed c7a864dc on main
    task: #3326900 ConfigManager::findConfigEntityDependenciesAsEntities()...

Status: Fixed » Closed (fixed)

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