ConfigSchemaChecker doesn't refresh the cache on module install

Created on 25 December 2024, 27 days ago

Problem/Motivation

When installing a module and trying to save the module configs in the same request, like this:

$this->moduleInstaller->install(['my_module]);
$config = $this->configFactory->getEditable('my_module.settings');
$config->save();

in the functional tests context we have an error:
Drupal\Core\Config\Schema\SchemaIncompleteException: No schema for my_module settings in Drupal\Core\Config\Development\ConfigSchemaChecker->onConfigSave() (line 91 of core/lib/Drupal/Core/Config/Development/ConfigSchemaChecker.php).

But in the browser, without the test context, we don't have this error.

Steps to reproduce

1. Create an action that installs a module and then - saves the module configuration.
2. Run this action manually - it will work well.
3. Run this action in a functional test - you will get the error.

Proposed resolution

This happens because in the functional test context, in the file core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php we add a custom service:

  protected function prepareSettings() {
      ...
      $services['services']['testing.config_schema_checker'] = [
        'class' => ConfigSchemaChecker::class,
        'arguments' => ['@config.typed', $this->getConfigSchemaExclusions(), $is_core_test],
        'tags' => [['name' => 'event_subscriber']],
      ];

And this service doesn't invalidate the cache for the definitions on module install.

A quick but ugly workaround for this is to add cache clear in the function onConfigSave() like this:

+     $this->typedManager->clearCachedDefinitions();
       $errors = $this->checkConfigSchema($this->typedManager, $name, $data, $this->validateConstraints);

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component

typed data system

Created by

πŸ‡¦πŸ‡²Armenia murz Yerevan, Armenia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @murz
  • πŸ‡¦πŸ‡²Armenia murz Yerevan, Armenia
  • πŸ‡¦πŸ‡²Armenia murz Yerevan, Armenia

    And here is a workaround (pretty ugly too) from the module side for the issue:

            $this->moduleInstaller->install(['my_module']);
            // A workaround for the issue https://www.drupal.org/project/drupal/issues/3495977
            // @todo Remove this when the proper fix is available.
            if ($this->container->has('testing.config_schema_checker')) {
              $configCheckerService = $this->container->get('testing.config_schema_checker');
              $reflection = new \ReflectionClass($configCheckerService);
              /** @var \Drupal\Core\Config\TypedConfigManagerInterface $configCheckerServiceConfigTyped */
              $configCheckerServiceConfigTyped = $reflection->getProperty('typedManager')->getValue($configCheckerService);
              $configCheckerServiceConfigTyped->clearCachedDefinitions();
            }
    
    
  • Merge request !10697created mr for configschemachecker β†’ (Open) created by Unnamed author
  • Pipeline finished with Failed
    25 days ago
    Total: 103s
    #379620
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave
  • First commit to issue fork.
  • Pipeline finished with Failed
    24 days ago
    Total: 123s
    #380128
  • Pipeline finished with Failed
    24 days ago
    Total: 2162s
    #380129
  • πŸ‡¬πŸ‡§United Kingdom oily Greater London

    Fixed PHPSTAN and PHPCS errors.

  • πŸ‡§πŸ‡ͺBelgium BramDriesen Belgium πŸ‡§πŸ‡ͺ

    Quick review code wise, there are some things which are not correct. Also still needs tests, and currently tests failures.

Production build 0.71.5 2024