Problem/Motivation
After updating Drupal core to 10.2.2, config inspector throws exception.
Symfony\Component\Validator\Exception\UnexpectedTypeException: Expected argument of type "array", "null" given in Drupal\Core\Validation\Plugin\Validation\Constraint\ValidKeysConstraintValidator->validate() (line 23 of /app/docroot/core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/ValidKeysConstraintValidator.php).
after debbuging, I can see that problem is with all search api solr configs. I don't know if problem is with solr configs or config inspector should catch this exception but:
/**
* Check schema compliance in configuration object.
*
* @param string $config_name
* Configuration name.
*
* @return array|bool
* FALSE if no schema found. List of errors if any found. TRUE if fully
* valid.
*
* @throws \Drupal\Core\Config\Schema\SchemaIncompleteException
*/
public function validateValues($config_name): ConstraintViolationListInterface {
if ($this->checkValues($config_name) === FALSE) {
throw new \LogicException("$config_name has no config schema.");
}
$config_data = $this->configFactory->get($config_name)->get();
$definition = $this->typedConfigManager->getDefinition($config_name);
$data_definition = $this->typedConfigManager->buildDataDefinition($definition, $config_data);
$typed_config = $this->typedConfigManager->create($data_definition, $config_data, $config_name);
// @todo Remove the preceding 3 lines in favor of th line below once this never is used to analyze Drupal before https://www.drupal.org/node/3360991.
// phpcs:disable
//$typed_config = $this->typedConfigManager->createFromNameAndData($config_name, $config_data);
// phpcs:enable
$violations = $typed_config->validate();
return $violations;
}
adnotation says it might be an array or bool but returned type is only ConstraintViolationListInterface.
/**
* Check schema compliance in configuration object.
*
* @param string $config_name
* Configuration name.
*
* @return array|bool
* FALSE if no schema found. List of errors if any found. TRUE if fully
* valid.
*/
public function validateValues($config_name): ConstraintViolationListInterface|bool {
if ($this->checkValues($config_name) === FALSE) {
throw new \LogicException("$config_name has no config schema.");
}
$config_data = $this->configFactory->get($config_name)->get();
$definition = $this->typedConfigManager->getDefinition($config_name);
$data_definition = $this->typedConfigManager->buildDataDefinition($definition, $config_data);
$typed_config = $this->typedConfigManager->create($data_definition, $config_data, $config_name);
// @todo Remove the preceding 3 lines in favor of th line below once this never is used to analyze Drupal before https://www.drupal.org/node/3360991.
// phpcs:disable
//$typed_config = $this->typedConfigManager->createFromNameAndData($config_name, $config_data);
// phpcs:enable
try {
$violations = $typed_config->validate();
return $violations;
}
catch (\Exception $e) {
return FALSE;
}
}
and then we need additional work in controller to process empty violations.
Steps to reproduce
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#9 | Screenshot 2024-02-13 at 17.12.34.png | 85.9 KB | 2dareis2do |
#9 | Screenshot 2024-02-13 at 17.12.21.png | 108.76 KB | 2dareis2do |
#8 | Screenshot 2024-02-13 at 16.57.36.png | 184.38 KB | 2dareis2do |
Issue fork config_inspector-3416934
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
2dareis2do CreditAttribution: 2dareis2do commentedI had problem with custom migration config
e.g.
also search api solr
i was able to uninstall search_api_solr and config is removed. Some of these are quite big. For migrations, these need to be
manually deletedset as a forced dependency to remove.Comment #3
2dareis2do CreditAttribution: 2dareis2do commentedMaybe there is an issue with search_api_solr config?
Comment #4
lamp5Do you have any suggestions ?
Comment #5
2dareis2do CreditAttribution: 2dareis2do commentedWell the it seems there is an expectation here that the schema is of a certain type/format/structure.
I am thinking either that assumption is either wrong here, or, search_api has implemented their config schema incorrectly.
Comment #6
gábor hojtsyLooks like the error is in core's code path. Not sure how we could pre-validate the schema so core does not fail this way. It is definitely a mismatch between core's understanding of how schema should be and the schema provided by your contrib module. But this does not look like the fault of config schema, rather the schema as applied when validating a config item.
If the exception is thrown all the way forward to the config inspector level, the inspector may be able to catch it. Is that the case?
Comment #7
2dareis2do CreditAttribution: 2dareis2do commentedSo looks like it is failing here
ok, so we also have this issue which appears to have been closed now.
https://www.drupal.org/node/3360991
So looks like that could be updated now. Not sure if that will make a difference here?
Comment #8
2dareis2do CreditAttribution: 2dareis2do commenteduploaded pic that shows that it seems to be validating all values. Seems to be tripping up here
Comment #9
2dareis2do CreditAttribution: 2dareis2do commentedDifficult to see what is breaking. Here are two configs that appear to break with the same or similar error
and
stacktrace for search_api_solr
I run out of memory trying to step through.
Comment #10
2dareis2do CreditAttribution: 2dareis2do commentedhttps://www.drupal.org/project/search_api_solr/issues/3415861
Comment #11
2dareis2do CreditAttribution: 2dareis2do commentedOk reading up on this it seems that one solution is to disable this change that exposes the validation errors. https://www.drupal.org/project/config_inspector/issues/3359418
Perhaps there also an issue in core with ValidKeysConstraintValidator?
Certain values are expected are set as null, but ValidKeysConstraintValidator is expecting it to be an array?
I am not sure why UnexpectedTypeException is thrown here as well, as it seems reasonable that a key value can be set to null without throwing an exception?
Comment #12
claudiu.cristeaI'm getting this for a
null
value of a mapping which is nullable. Maybe we need #3364109: Configuration schema & required values: add test coverage for `nullable: true` validation support in Drupal 10.2?Comment #13
megan_m CreditAttribution: megan_m at Woolwich Web Works for OCASI commentedApplying the patch for issue #3364109 linked in the previous comment resolves this error for me.
Comment #14
2dareis2do CreditAttribution: 2dareis2do commented@megan_m which patch and which version of Drupal?Thank you @megan_m. Rerolled patch, uploaded and seems to work. i.e. no longer getting fatal error at /admin/reports/config-inspector/search_api_solr.solr_cache.cache_document_default_7_0_0/list
Comment #15
2dareis2do CreditAttribution: 2dareis2do commentedOK @alexpott states on slack.
Comment #16
2dareis2do CreditAttribution: 2dareis2do commentedConfig inspector has also been updated see
https://git.drupalcode.org/project/config_inspector/-/commit/6799e12839f...
It seems plausible that this change has broken config inspector when running in 10.2.x or later
Comment #17
2dareis2do CreditAttribution: 2dareis2do commentedUpdating as it appears latest update to config_inspector breaks compatibility with 10.x
see
https://www.drupal.org/project/drupal/issues/3364109#comment-15504971
Comment #18
2dareis2do CreditAttribution: 2dareis2do commentedMy guess is this can be merged into 11.x release and we can probably revert for 10.x compatibility
Comment #19
wim leersI made Config Inspector compatible with Drupal 10.2 in #3413217: Make tests pass on Drupal 10.2.
Investigating… 🕵️
Comment #20
wim leersLinking the issues that @2dareis2do has mentioned.
#16: Yes, https://git.drupalcode.org/project/config_inspector/-/commit/6799e12839f... landed for Config Inspector 2.1.8 — that's the commit for the issue I linked in my previous comment.
Comment #21
wim leersWell … the issue title is very broad, but AFAICT this has only ever been reported or reproduced for
search_api_solr
config, and even then only for migrated-from-Drupal 7 config for that module? 😅Comment #22
wim leers10.2.4
search_api
1.32, all is still well.search_api_solr
tip of the4.x
branch, currentlyb9608ac764efa3df72a90e8102712ce3c36c3a17
. BTW, this includes the following scary message: after installation 🫣/admin/reports/config-inspector
👍:Repeating the same steps for Drupal 11 does not trigger a crash.
Comment #23
wim leersRoot cause analysis
Part one: the "trigger"
The "trigger" is
in
config/schema/search_api_solr.cache.schema.yml
Drupal core config schema infrastructure
Drupal core introduced the ability to mark
type: sequence
as nullable in #1978714: Entity reference doesn't update its field settings when referenced entity bundles are deleted. But … it implemented it at theArrayElement
level, which is the parent class of bothSequence
(type: sequence
) andMapping
(type: mapping
).Not a single config schema in Drupal core specifies
nullable: true
for atype: mapping
. So when</code> was introduced in #3324150: Add validation constraints to config_entity.dependencies, that was overlooked. <code>10.1.0
was the first release in which it shipped.Subsequently, #3364109: Configuration schema & required values: add test coverage for `nullable: true` validation support landed after
10.3.x
and11.x
and it contains this:… which is why @2dareis2do reported at #3415861-15: ValidKeysConstraintValidator thrown by Config Inspector on Drupal 10.1.x and 10.2.x due to core bug triggered only by Config Inspector that that "fixed" the problem.
Conclusion
10.1
and subsequent releases, but does not apply it to any non-core config! Precisely because we knew that not all contrib config would be compliant/correctly use config schema … and because we knew that Drupal core's config validation infrastructure was not yet in a good enough place, we'll only be able to consider it ready for prime time once at a minimum all core config is validatable.10.1.x
and10.2.x
!The only possible way forward is … to make Config Inspector "simulate" the part of the fix that #3364109: Configuration schema & required values: add test coverage for `nullable: true` validation support landed, and which I quoted above. So I'll do that next 🤓 This will only be necessary for as long as this module supports Drupal <10.3.
Comment #24
wim leersComment #26
wim leersComment #27
wim leersComment #28
wim leersHah, looks like @claudiu.cristea caught the root cause 2 weeks ago in #12. I wish you had renamed the issue title, @claudiu.cristea, then your crucial single line would've been lost in this ocean of long comments that only talked about symptoms 😄 Either way, fixed now — will get a release out shortly.
Comment #29
2dareis2do CreditAttribution: 2dareis2do commentedthanks @Wim Leers.
fyi iirc I also had similar with migrate yaml config and not specifying enforced dependencies.
Comment #30
wim leersThat must've been with the
migrate_plus
module then, because Drupal core's migration system is completely independent of the configuration system.Did the commit above fix that too? I'd appreciate it if you could test + confirm that :) (A quick scan of https://git.drupalcode.org/project/migrate_plus/-/tree/6.0.x/config/sche... reveals no occurrences of
nullable: true
, so it seems that's an unrelated problem. If you can still reproduce that problem, could you please create a new/separate issue for that? 🙏)Comment #32
idebr CreditAttribution: idebr at iO commented@Wim Leers this issue was marked fixed but the merge request is still open. Could you merge it and tag a new release?
Comment #33
pdcarto CreditAttribution: pdcarto as a volunteer and at Born-Digital, Inc. commentedPaging @Wim Leers - the issue branch has still not been merged (there is no MR).