Problem/Motivation

Pulled from original post

So far, it was always a property inside a views filter, where it expects value to be a string but it's an array.

Pulled from #44

This is specific to views because views defines generic default schema for certain things, like filter plugin values. The config schema system can handle missing config schema, what it can't deal with is mismatches where it's expecting a scalar but actually receives a mapping/array/complex data

Steps to reproduce

Generate a mismatch config schema and try to save it.

Proposed resolution

In the save function for Config.php wrap the code that attempts castValue() in a try/catch block. And loop through the data vs calling it as is.
Log issues vs throw error

Remaining tasks

Update issue summary

User interface changes

NA

API changes

NA

Data model changes

NA

Release notes snippet

NA

Original Post

I had multiple 8.4 upgrades failing with an error like this so far:

#0  Drupal\Core\Config\Schema\ArrayElement->get() called at [/core/lib/Drupal/Core/Config/StorableConfigBase.php:179]
#1  Drupal\Core\Config\StorableConfigBase->castValue() called at [/core/lib/Drupal/Core/Config/StorableConfigBase.php:211]
#2  Drupal\Core\Config\StorableConfigBase->castValue() called at [/core/lib/Drupal/Core/Config/StorableConfigBase.php:211]
#3  Drupal\Core\Config\StorableConfigBase->castValue() called at [/core/lib/Drupal/Core/Config/StorableConfigBase.php:211]
#4  Drupal\Core\Config\StorableConfigBase->castValue() called at [/core/lib/Drupal/Core/Config/StorableConfigBase.php:211]
#5  Drupal\Core\Config\StorableConfigBase->castValue() called at [/core/lib/Drupal/Core/Config/StorableConfigBase.php:211]
#6  Drupal\Core\Config\StorableConfigBase->castValue() called at [/core/lib/Drupal/Core/Config/StorableConfigBase.php:211]
#7  Drupal\Core\Config\StorableConfigBase->castValue() called at [/core/lib/Drupal/Core/Config/Config.php:212]
#8  Drupal\Core\Config\Config->save() called at [/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php:280]
#9  Drupal\Core\Config\Entity\ConfigEntityStorage->doSave() called at [/core/lib/Drupal/Core/Entity/EntityStorageBase.php:392]
#10 Drupal\Core\Entity\EntityStorageBase->save() called at [/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php:259]
#11 Drupal\Core\Config\Entity\ConfigEntityStorage->save() called at [/core/lib/Drupal/Core/Entity/Entity.php:377]
#12 Drupal\Core\Entity\Entity->save() called at [/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php:637]
#13 Drupal\Core\Config\Entity\ConfigEntityBase->save() called at [/core/modules/views/views.post_update.php:213]
#14 {closure}()
#15 array_walk() called at [/core/modules/views/views.post_update.php:214]
#16 views_post_update_revision_metadata_fields() called at [/core/includes/update.inc:241]
#17 update_invoke_post_update() called at [/vendor/drush/drush/commands/core/drupal/batch.inc:163]
#18 _drush_batch_worker() called at [/vendor/drush/drush/commands/core/drupal/batch.inc:111]
#19 _drush_batch_command() called at [/vendor/drush/drush/includes/batch.inc:98]
#20 drush_batch_command() called at [/vendor/drush/drush/commands/core/drupal/update.inc:193]

So far, it was always a property inside a views filter, where it expects value to be a string but it's an array.

While it's bad that those mismatches exists, we ignore missing schema outside of tests, so I think we should also ignore those kind of problems, possibly just log them, without failing the update.

Example errors:
InvalidArgumentException: The configuration property display.default.display_options.filters.type.value.audio doesn't exist. in Drupal\Core\Config\Schema\ArrayElement->get() (line 76 of /h
InvalidArgumentException: The configuration property display.default.display_options.filters.type_1.value.image doesn't exist.

Issue fork drupal-2925890

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

Berdir created an issue. See original summary.

berdir’s picture

Status: Active » Needs review
StatusFileSize
new798 bytes

Status: Needs review » Needs work

The last submitted patch, 2: config-cast-exception-2925890-2.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

dawehner’s picture

@Berdir
Did you figured out which part of the configuration was wrong in the first place? Ideally update.php should have finished already at that point int ime.

berdir’s picture

Which part yes, because I did fix it manually, but not why.

One example was a changed (I think) People view and it had a filter with a bogus value. Checking the diff, the filter is uid_raw and the change that I had to do was basically this:

-          value:
-            min: ''
-            max: ''
-            value: '0'
+         value: '0'

However, looking a bit closer, I see that the nested structure with min/max is also the one that is currently in core.

The difference seem to be that core uses plugin_id: numeric while my version uses plugin_id: field, which doesn't make any sense because this is a filter.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new4.43 KB

Ok, updated the test to instead look for a log message. Also expanded the try/catch to cover validation as.

berdir’s picture

Status: Needs review » Needs work

Discussed with @alexpott, I'll go back to just catching exceptions from castValue()

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

jordanpagewhite’s picture

StatusFileSize
new4.49 KB

I rerolled the patch in #6 for Drupal 8.6.x.

robpowell’s picture

Status: Needs work » Needs review

rerunning tests putting in needs review

remyyyyy’s picture

PHP message: Uncaught PHP Exception InvalidArgumentException: "The configuration property display.default.display_options.filters.field_xxx_target_id.value.min doesn't exist." at /core/lib/Drupal/Core/Config/Schema/ArrayElement.php line 76"

After applying the patch #10, i can save my view and error has gone !

Drupal 8.7.3

Thank you all

jacob.embree’s picture

Version: 8.6.x-dev » 8.8.x-dev
Status: Needs review » Reviewed & tested by the community

I can confirm this fixes the issue. I'm on Drupal 8.8. The patch also applies to 9.0.x.

I'd love to know how fix the underlying issue causing the exception.
EDIT: Figured it out. I provided a Views filter plugin that extended the Date one, but did not also provide config for it.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

I'm not sure that the approach in this patch is correct. The problem is that is we stop processing the schema then the rest of the values in the view will not be correctly cast.

I think in order to do this correctly we should:

  • Change the exception thrown by \Drupal\Core\Config\Schema\ArrayElement::get() to be something more specific.
  • Catch this exception in \Drupal\Core\Config\StorableConfigBase::castValue()
oriol_e9g’s picture

Same problem trying to update views_bulk_operations module - Update #8034

Failed: InvalidArgumentException: The configuration property display.edita_elements.display_options.fields.views_bulk_operations_bulk_form.selected_actions.0.action_id.action_id doesn't exist. a Drupal\Core\Config\Schema\ArrayElement->get()

Not only works with invalid structures also protects for missing configs. Issue still needs work but in my case this patch fixes the problem without side effects.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

br0ken’s picture

Version: 8.9.x-dev » 9.0.x-dev
Status: Needs work » Needs review
Issue tags: +Needs tests
StatusFileSize
new3.08 KB

The patch that takes the approach proposed in #14.

br0ken’s picture

StatusFileSize
new3.13 KB
new1.26 KB
jeqq’s picture

Status: Needs review » Reviewed & tested by the community

The patch from #18 fixes the bug for me. Thanks!

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

@BR0kEN thanks for the change in implementation.

We still need automated test coverage here.

alexpott’s picture

+++ b/core/lib/Drupal/Core/Config/Schema/ArrayElement.php
@@ -72,9 +72,7 @@ public function get($name) {
-      throw new \InvalidArgumentException("The configuration property $name doesn't exist.");

+++ b/core/lib/Drupal/Core/Config/Schema/ConfigSchemaNoSuchPropertyException.php
@@ -0,0 +1,44 @@
+/**
+ * The exception to raise when the config schema has no given property.
+ */
+class ConfigSchemaNoSuchPropertyException extends \RuntimeException {

I think the new exception should extend \InvalidArgumentException for BC purposes.

br0ken’s picture

StatusFileSize
new1.77 KB

@alexpott yeah, that makes sense.

br0ken’s picture

StatusFileSize
new3.14 KB

Forgot to add the exception.

pasqualle’s picture

Version: 9.0.x-dev » 9.1.x-dev

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

odegard’s picture

Needed this patch for the notify_to_slack module. Worked great on 9.1.6.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

kim.pepper’s picture

Issue tags: +#pnx-sprint
berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new3.25 KB

Reroll for 9.3.

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

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

marios anagnostopoulos’s picture

I tried the patch in #23 since I am in 9.2 and it fixed this issue.
In my case I was trying to save a search_api_language filter with the required option checked and a default language selected. (Just for reference).

marios anagnostopoulos’s picture

While the view gets saved normally, I get the same error on config import.
Can someone else confirm this?

Edit: Not the same error (my bad)
The ConfigSchemaNoSuchPropertyException is the one I get, and since this is caught and logged in castValue, I guess it is normal to be shown in cli, so i guess this behaviour is intended. Is there any way to suppress this?

Otherwise I have no issue so far... +1 for RTBC.

kasey_mk’s picture

@marios-anagnostopoulos - confirmed. I get the same behavior with patch #29 on 9.3.2

Edited to add: I seem to have solved the config-import error on my build by changing the plugin_id for the troublesome filter in views.view.VIEWNAME.yml from comment_ces_last_updated to numeric though I still need patch #29 to save the view via the UI (which does not overwrite the manually-updated plugin_id value).

igonzalez’s picture

Patch #29 works for me in 9.3.2

marios anagnostopoulos’s picture

#33 this does not sound like an intended behavior.

afsch’s picture

StatusFileSize
new3.7 KB

I made an update for #29

ranjith_kumar_k_u’s picture

StatusFileSize
new3.79 KB
new826 bytes

Fixed CS errors.

pasqualle’s picture

The patch seems to be working, and the code changes look good.
Would it be possible to create a test, which fails without this patch?

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

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

rakan_d’s picture

Patch #29 works for me in 9.3.9

kasey_mk’s picture

I was able to actually fix the config that was missing in my use case on Fatal error when trying to save a View, getting InvalidArgumentException (patch #33). With that fix in place, I was able to remove the patch from this thread.

smustgrave’s picture

Status: Needs review » Needs work

Moving to NW for the tests.

smustgrave’s picture

Also since this bug was reported for 8.4 an issue summary update probably is needed.

Is this even still an issue?

berdir’s picture

Yes, it's still an issue. And yes, it's a workaround in case of missing config schema.

This is specific to views because views defines generic default schema for certain things, like filter plugin values. The config schema system can handle missing config schema, what it can't deal with is mismatches where it's expecting a scalar but actually receives a mapping/array/complex data.

Maybe we can fix the root case by removing those wildcard schema fallback definitions, I'm not sure. I'm also not sure about a test, because this about dealing with invalid schema definitions, which core doesn't have and would actually fail tests on its own, so we'd need to ignore that.

ankondrat4’s picture

StatusFileSize
new4.22 KB

I rerolled the patch in #10 for Drupal 9.4.x

ankondrat4’s picture

StatusFileSize
new4.5 KB

Fixed errors after end test for Drupal 9.4.x

ankondrat4’s picture

I has tested patches #37, #39 - its works, but strange behavior of them. After end of apply this patches they created 3 files:
- docroot/core/lib/Drupal/Core/Config/Schema/ConfigSchemaNoSuchPropertyException.php
- docroot/core/b/lib/Drupal/Core/Config/Schema/ConfigSchemaNoSuchPropertyException.php
- docroot/core/core/lib/Drupal/Core/Config/Schema/ConfigSchemaNoSuchPropertyException.php

smustgrave’s picture

@ankondrat4 when you upload a patch can you please upload an interdiff so we can see what changed.

ankondrat4’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work

#46 is failing testing and no interdiff was provided to help review.

Also needs IS update per the tag.

ankondrat4’s picture

Status: Needs work » Needs review
StatusFileSize
new3.41 KB

Sorry, interdiff 45-46

ankondrat4’s picture

Status: Needs review » Needs work
smustgrave’s picture

Issue summary: View changes

Started the IS update but if someone more familiar with the issue could fill in the missing pieces.

As far as the test failure in #46 with this change maybe that test should be updated?

smustgrave’s picture

Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Needs tests, -Needs issue summary update
StatusFileSize
new517 bytes
new2.95 KB
new5.12 KB

@ankondrat4 you don't need to hide your files. If it's valid and helped move the issue forward leave up for others to help or comment on.

Took a shot at an updated IS.

Believe with this change the failing test case from #46 just needed to be updated.

Adding a tests-only patch as well from #46

The last submitted patch, 54: 2925890-54-tests-only.patch, failed testing. View results

ankondrat4’s picture

@smustgrave, ok. Thank you.

drdam’s picture

That fix exception in config saving !

Test against 9.4.6 (php 8.1) => RTBC

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

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now 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.

podarok’s picture

Status: Needs review » Reviewed & tested by the community

as per #57

catch’s picture

Status: Reviewed & tested by the community » Needs work

The patch in #54 is based on the patch in #45, but this a re-roll of the patch in #10 which undoes all of the work/feedback from #14 to #37.

marios anagnostopoulos’s picture

StatusFileSize
new774 bytes

I created an issue fork and pushed the changes up to #37 which apply to 10.1.x
I didn't include the tests provided #54 since the patch in that comment was based on the older implementations (as per #60) and because I was not sure if they would be relevant (as per #44)

If you think that they should be included, feel free to commit and update the issue.

The interdiff I provide is just the missing one between 29 and 37.

matthieuscarset’s picture

Confirmed patch #54 works for me on 9.5.3

maxmendez’s picture

Confirmed patch #54 works for me on 9.5.7

Version: 10.1.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, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

sassafrass’s picture

Confirmed patch #54 works for me on 10.1

isolate’s picture

Version: 11.x-dev » 9.5.x-dev
StatusFileSize
new1.49 KB

Updated for 9.5.10

juanl’s picture

StatusFileSize
new1.52 KB
new1.52 KB

Updated for 9.5.11

juanl’s picture

borisson_’s picture

Issue tags: +Configuration schema

#3347842: Deprecate the trusted data concept in configuration will remove the trusted data concept entirely, and I think what this issue is doing, ignoring config schema errors, is the complete opposite of all of the config schema validation work we've been doing lately.

This is because contrib/custom code doesn't always provide a correct schema, and instead of hiding the errors, I think we should guide maintainers to write correct and complete schema's.

davidjguru’s picture

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.

socialnicheguru’s picture

For #65 watchdog_exception is deprecated. https://www.drupal.org/node/2932520

natnatalia’s picture

StatusFileSize
new5.21 KB

Updated for Drupal 10.3.0

pifagor’s picture

@natnatalia Part for Config.php is present in version 10.3.0, so the patch cannot be applied. Maybe only the tests need updating

gcalex5’s picture

StatusFileSize
new5.15 KB

Re-roll #73 to remove the /site/ prefix that was preventing it from applying.

sokolff’s picture

I can confirm that patch #75 works fine for Drupal 10.3.0. Thank you!

olmyr’s picture

Hello,
#75 works with 11.0.4

francismak’s picture

Patch #75 works for 10.3.6, thank you! Putting more details here.

For our case, we are using a 'or' operator in views when filtering a taxonomy term.
Our config import was working in 10.2, but got error in 10.3.6

The configuration property display.block_1.display_options.filters.field_data_target_id.value.983 doesn't exist.

In the config yml, I removed the values with issues, and replaced with {} instead, and able to import. Then navigate to that view, tried to add back the 'or' filtering to that term and save:

InvalidArgumentException: The configuration property display.block_1.display_options.filters.field_data_target_id.value.983 doesn't exist. in Drupal\Core\Config\Schema\ArrayElement->get() (line 95 of core/lib/Drupal/Core/Config/Schema/ArrayElement.php).

Once patch #75 applied, both import and view saving are now working properly.

hswong3i made their first commit to this issue’s fork.

bfuzze9898’s picture

Patch #75 applies for 10.4.3.

sea2709 made their first commit to this issue’s fork.

malcomio made their first commit to this issue’s fork.

malcomio’s picture

StatusFileSize
new5.75 KB

Patch 75 no longer applies for 10.5.x - I've re-rolled it in https://git.drupalcode.org/project/drupal/-/merge_requests/12956/diffs and attached an updated patch.

electrokate’s picture

StatusFileSize
new5.24 KB

Here is a re-rolled patch which works with Drupal 11.2.3.

fskreuz changed the visibility of the branch 2925890-invalid-config-structures to hidden.

fskreuz changed the visibility of the branch 10.1.x to hidden.

phjou’s picture

StatusFileSize
new5.58 KB

Seems like it does not apply anymore, rerolled from #88

nireneko’s picture

StatusFileSize
new5.73 KB

Patch for 10.5.3

sagesolutions’s picture

Patch #85 (2925890-84.patch) works for me on Drupal 10.5.6

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

hchonov’s picture

StatusFileSize
new5.69 KB