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.
| Comment | File | Size | Author |
|---|---|---|---|
| #94 | 2925890-94-11.3.x.patch | 5.69 KB | hchonov |
| #91 | 2925890-91-10-5-3.diff | 5.73 KB | nireneko |
| #90 | 2925890-90.patch | 5.58 KB | phjou |
| #86 | invalid_config_structure_2925890.patch | 5.24 KB | electrokate |
| #85 | 2925890-84.patch | 5.75 KB | malcomio |
Issue fork drupal-2925890
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
berdirComment #4
dawehner@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.
Comment #5
berdirWhich 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:
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: numericwhile my version uses plugin_id: field, which doesn't make any sense because this is a filter.Comment #6
berdirOk, updated the test to instead look for a log message. Also expanded the try/catch to cover validation as.
Comment #7
berdirDiscussed with @alexpott, I'll go back to just catching exceptions from castValue()
Comment #10
jordanpagewhite commentedI rerolled the patch in #6 for Drupal 8.6.x.
Comment #11
robpowellrerunning tests putting in needs review
Comment #12
remyyyyyPHP 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
Comment #13
jacob.embree commentedI 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.
Comment #14
alexpottI'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:
Comment #15
oriol_e9gSame problem trying to update views_bulk_operations module - Update #8034
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.
Comment #17
br0kenThe patch that takes the approach proposed in #14.
Comment #18
br0kenComment #19
jeqq commentedThe patch from #18 fixes the bug for me. Thanks!
Comment #20
alexpott@BR0kEN thanks for the change in implementation.
We still need automated test coverage here.
Comment #21
alexpottI think the new exception should extend \InvalidArgumentException for BC purposes.
Comment #22
br0ken@alexpott yeah, that makes sense.
Comment #23
br0kenForgot to add the exception.
Comment #24
pasqualleComment #26
odegard commentedNeeded this patch for the notify_to_slack module. Worked great on 9.1.6.
Comment #28
kim.pepperComment #29
berdirReroll for 9.3.
Comment #31
marios anagnostopoulos commentedI 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).
Comment #32
marios anagnostopoulos commentedWhile 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.
Comment #33
kasey_mk commented@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_updatedtonumericthough I still need patch #29 to save the view via the UI (which does not overwrite the manually-updated plugin_id value).Comment #34
igonzalez commentedPatch #29 works for me in 9.3.2
Comment #35
marios anagnostopoulos commented#33 this does not sound like an intended behavior.
Comment #36
afschI made an update for #29
Comment #37
ranjith_kumar_k_u commentedFixed CS errors.
Comment #38
pasqualleThe patch seems to be working, and the code changes look good.
Would it be possible to create a test, which fails without this patch?
Comment #40
rakan_d commentedPatch #29 works for me in 9.3.9
Comment #41
kasey_mk commentedI 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.
Comment #42
smustgrave commentedMoving to NW for the tests.
Comment #43
smustgrave commentedAlso since this bug was reported for 8.4 an issue summary update probably is needed.
Is this even still an issue?
Comment #44
berdirYes, 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.
Comment #45
ankondrat4 commentedI rerolled the patch in #10 for Drupal 9.4.x
Comment #46
ankondrat4 commentedFixed errors after end test for Drupal 9.4.x
Comment #47
ankondrat4 commentedI 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
Comment #48
smustgrave commented@ankondrat4 when you upload a patch can you please upload an interdiff so we can see what changed.
Comment #49
ankondrat4 commentedComment #50
smustgrave commented#46 is failing testing and no interdiff was provided to help review.
Also needs IS update per the tag.
Comment #51
ankondrat4 commentedSorry, interdiff 45-46
Comment #52
ankondrat4 commentedComment #53
smustgrave commentedStarted 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?
Comment #54
smustgrave commented@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
Comment #56
ankondrat4 commented@smustgrave, ok. Thank you.
Comment #57
drdam commentedThat fix exception in config saving !
Test against 9.4.6 (php 8.1) => RTBC
Comment #59
podarokas per #57
Comment #60
catchThe 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.
Comment #61
marios anagnostopoulos commentedI 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.
Comment #62
matthieuscarset commentedConfirmed patch #54 works for me on 9.5.3
Comment #63
maxmendez commentedConfirmed patch #54 works for me on 9.5.7
Comment #65
sassafrass commentedConfirmed patch #54 works for me on 10.1
Comment #66
isolate commentedUpdated for 9.5.10
Comment #67
juanl commentedUpdated for 9.5.11
Comment #68
juanl commentedComment #69
borisson_#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.
Comment #70
davidjguruComment #72
socialnicheguru commentedFor #65 watchdog_exception is deprecated. https://www.drupal.org/node/2932520
Comment #73
natnatalia commentedUpdated for Drupal 10.3.0
Comment #74
pifagor@natnatalia Part for Config.php is present in version 10.3.0, so the patch cannot be applied. Maybe only the tests need updating
Comment #75
gcalex5 commentedRe-roll #73 to remove the
/site/prefix that was preventing it from applying.Comment #76
sokolff commentedI can confirm that patch #75 works fine for Drupal 10.3.0. Thank you!
Comment #77
olmyr commentedHello,
#75 works with 11.0.4
Comment #78
francismak commentedPatch #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.
Comment #81
bfuzze9898 commentedPatch #75 applies for 10.4.3.
Comment #85
malcomio commentedPatch 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.
Comment #86
electrokate commentedHere is a re-rolled patch which works with Drupal 11.2.3.
Comment #90
phjouSeems like it does not apply anymore, rerolled from #88
Comment #91
nireneko commentedPatch for 10.5.3
Comment #92
sagesolutions commentedPatch #85 (2925890-84.patch) works for me on Drupal 10.5.6
Comment #94
hchonov