Problem/Motivation
We have a nice ConfigSchemaChecker in core which we use for testing. We do not enable it by default (i.e. "on production") for performance reasons and because schema violations are generally developer errors and shouldn't occur on stable systems.
However, for local development environments, it would be great to enable ConfigSchemaChecker.
Proposed resolution
We already have a mechanism for standardizing best-practice development settings: example.settings.local.php and development.services.yml.
Let's add \Drupal\Core\Config\Testing\ConfigSchemaChecker to development.services.yml. Consider adding a todo to move it out of the Testing namespace in D9.
And decide on the namespace. There was an initial suggestion of 'Drupal\Core\Config\Schema\ConfigSchemaChecker'. And later the patch used '\Drupal\Core\Config\Devel\ConfigSchemaChecker', which was changed to '\Drupal\Core\Config\Development\ConfigSchemaChecker'.
Is the current namespace '\Drupal\Core\Config\Development\ConfigSchemaChecker' the one to use or something else?
Update 15-04-2025:
\Drupal\Core\Config\Development\ConfigSchemaChecker seems like a decent enough namespace.
Remaining tasks
| Task | Novice task? | Contributor instructions | Complete? |
|---|---|---|---|
| Create a patch | Instructions | ||
| Reroll the patch if it no longer applies. | Instructions |
User interface changes
None.
API changes
Because we recommend copying example.settings.local.php directly and that directly includes development.services.yml this constitutes a change in behavior for people that have the local settings enabled. I.e. if they violating config, they will not be able to re-save the config after this change.
Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #104 | 2625212-nr-bot.txt | 1.56 KB | needs-review-queue-bot |
Issue fork drupal-2625212
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
dawehnerNice idea!
Comment #3
okay19 commentedHere is a patch for this issue.
Comment #4
okay19 commentedComment #5
cs_shadow commentedPlease add a todo comment in the `ConfigSchemaChecker` class suggesting it to be moved out of `Testing` namespace in D9 so that we don't forget to do so.
Comment #6
okay19 commentedAdded the todo in the ConfigSchemaChecker class.
Comment #7
okay19 commentedComment #8
cs_shadow commentedLGTM
Comment #9
alexpott@todo's without issues aren't correct. Plus we could copy the class to the "correct" place now and just make the existing on extend from that.
I think this needs to be be tagged with...
Otherwise it is not going to work.
Comment #10
krishnan.n commented@alexpott:
name: event_subscriberbecause theConfigSchemaCheckerimplementEventSubscriberInterface, correct? So, we just need to add the line you'd mentioned?We can create a patch once we have the namespace in place.
Comment #11
tstoeckler@krishnan: I think an appropriate namespace would be
Drupal\Core\Config\Schema\ConfigSchemaChecker. Needless to say, you or @alexpott, or anyone else: feel free to disagree.Yes, exactly. Thanks @alex-eagle-eye-pott for catching that! Totally missed that in my review.
Comment #12
krishnan.n commentedThink this patch is invalid and here more for reference -- don't think the directory rename is in the patch. Did a 'git diff -M10%' but that doesn't seem to have worked; putting this anyways so someone else (or a clearer me) can clean up later.
Comment #13
cilefen commentedYou cannot change the namespace without also moving the class to the new directory, as in, on the file system.
Comment #14
dawehnerDoes someone mind explaining how this actually works at the moment? How can Drupal find this class?
Comment #15
krishnan.n commentedThanks to cilefen; have the directory move as part of the patch (Hopefully)
Comment #16
rashid_786 commentedComment #18
cilefen commentedSomeone please update the issue summary when the namespace decision is made. This is going with "Devel" for the namespace.
Comment #19
cilefen commentedComment #20
cilefen commentedOops, I messed up the first line here.
Comment #22
snehi commentedChanged it. Please review.
Comment #24
tstoecklerNot excited about the "Devel" namespace, but OK...
Please add an appropriate use statement instead of referencing the full namespace inline.
The latest patch seems to miss the adding of the new file, which is why it fails. Also it would be good to roll the patch with the
-Coption, so that the patch is smaller.Comment #25
cilefen commented@tstoeckler I do not understand your namespace suggestion in #11 and I regret ignoring it rather than just saying so.
Comment #26
dawehnerJust a nitpick, let's use 'Development' instead of 'Devel', we don't use abbrev. in our variables, so ideally also not in namespaces.
Comment #27
cilefen commentedComment #30
quietone commentedPatch no longer applies.
Updated issue summary to indicate that a reroll is needed and to indicate that the namespace needs to be agreed on. At least, it wasn't clear to me that there is agreement on using the 'Development' namespace.
Leaving as novice for the reroll.
Comment #31
kostyashupenkoreroll of #27. There was only one little conflict at this file /core/lib/Drupal/Core/Config/Testing/ConfigSchemaChecker.php
Comment #32
dawehnerJust some nitpicks. I think this looks overall great.
This is no longer needed
Let's update that to 8.3.0
Comment #33
wim leersI think this at least major for the DX. Agree this looks great!
Comment #34
dawehnerBoth nitpicks can be fixed on commit.
Comment #35
alexpottSo it is eay to tell no unnecessary changes have occurred in the new class. See https://www.drupal.org/documentation/git/configure
ConfigSchemaChecker::class and a use statement would be preferable.
Comment #36
faline commentedCreating the patch with changes in #32 and #35
(including gitconfig:
)
Comment #37
tstoecklerThis should be
ConfigSchemaChecker::class(without quotes)Comment #38
wim leersThis file is no longer being moved.
ConfigSchemaChecker::classThe current code will fail.
Comment #39
faline commentedSorry @Wim Leers, I should remove the `core/lib/Drupal/Core/Config/Testing/ConfigSchemaChecker.php` file?
Comment #40
faline commentedFixing Patch
Comment #41
faline commentedComment #42
wim leersLooks perfect :)
Comment #44
alexpottI missed one... sorry...
Also as we're deprecating something we should have a CR to tell developers about this.
Comment #45
faline commented@alexpott on BrowserTestBase is also call for use Drupal\Core\Config\Testing\ConfigSchemaChecker. Should I change here to use the Drupal\Core\Config\Development\ConfigSchemaChecker, right?
Comment #46
faline commentedupdating patch
Comment #48
faline commentedFixing patch #46
Comment #49
alexpottYep we need to fix the usage in \Drupal\Tests\BrowserTestBase - still not fixed in #48 - well spotted to @faline. And there is an @see to fix in there too.
Comment #50
faline commentedSorry @alexpott I forgot to include the change on BrowserTestBase.
Now the fixed patch included the @see fiz too.
Comment #51
faline commentedComment #53
tstoecklerThanks for your great effort on this @faline! I reeeaallly wanted to RTBC this one, but I looked at the changes to the @see statements, and I think they're not correct. Concrete notes below:
We should keep the old reference. I think it's good to add the one in simpletest Module, but the old one is still (just as) valid.
Same here.
Or we could remove all current @see's and just add a @see to the new class.
This makes it seems like "checker" is a separate namespace. Maybe "config.schema_checker" ?
Comment #54
faline commented@tstoeckler I keep both @see references, old and new one, what do you think?
Comment #55
tstoecklerAwesome, thank you very much!
Comment #56
tstoecklerOh, we still need a change record, but other than that, this is good to go.
Comment #57
faline commented@tstoeckler I forgot to change this point: @see on \Drupal\Tests\BrowserTestBase as @alexpott told on comment #49
Comment #59
tstoecklerThanks @faline for the change notice, this is now ready to go.
Comment #61
joelpittetTestbot failure, resetting status due to https://www.drupal.org/node/2828045
Comment #62
catchCommitted/pushed to 8.3.x, thanks!
Comment #65
tstoecklerThis has caused problems for upgrade functions which save config, so I think this should be rolled back.
At the very least we should check whether the config is explicitly trusted, and if so, we should not do anything.
Even then, though, this might be a risky change in case update functions (wrongly) do not trust data. See #2838370: system_update_8200 is not trusting the data when re-saving all configs but it should for an example of this.
Since this included a class rename, though, which makes sense regardless of enabling it by default or not, I don't think this should be rolled back in the sense of
git revert. Instead I think we should do the attached patch.Comment #66
tstoecklerComment #67
dawehnerOn top of that I've also people struggling to use basically anything in the views UI due to issues like #2623568: Config schema of argument_default plugins is incorrect and some others. Of course they could change their
development.services.yml, but that's not obvious.Given that we should probably roll it back and figure out how to at least solve the update problem, as described by @tstoeckler
Comment #69
catchCommitted #64 to roll this back.
Comment #73
chi commentedWhat if the checker will emit an error instead of throwing an exception? We could make the behavior configurable to preserve exceptions for testing. This checker is really needed for local development.
Comment #74
chi commentedMeanwhile I just created a simple module to test how it could work.
Comment #75
alexpottComment #79
jhedstromThis is at NW if it's still something being pursued at all.
Comment #85
mxr576We are using config schema checker as a default dev requirement in our all our projects and possibly there is a similar issue with it that was mentioned in #65. I do not have full details yet, but it seems when contrib modules changes their config schema in a release and also remove their old config definitions (afaik there is no policy for not doing that in a non-major version) then the update process (updb && cim) fails false positively with config scheme validation error.
Eg.: https://www.drupal.org/project/eu_cookie_compliance/issues/3210365#comme...
Comment #86
tstoecklerI was going to comment in that issue that the problem is that in
hook_update_N()the$has_trusted_dataparameter should be set to TRUE when saving config and that that would avoid the use of the schema checker. While it's true that that parameter should be set, looking at the code I don't think the schema checker would actually be influenced by that. I think we should open an issue for that as that means the schema checker cannot be activated during config updates inhook_update_N()which in turn means that it's not safe to "Just always have it on" even for development environments. I may be totally mistaken, though, I didn't play around with this locally.Comment #87
berdirHad a crosspost.
> fails false positively with config scheme validation error.
That's not a false positive, that's the expected behavior then. Removing the schema means it's no longer valid. Yes, not, running it during updates might make sense, but even then, just removing the schema is tricky.
Drupal 9 now has a way to deprecate config schema, but that's AFAIK quite new and contrib won't have picked that up yet. But that's probably the way forward for most cases.
Comment #88
bircherWhat if we add the schema validation as a warning when one saves the config. (ie idea from #74)
I understand that we can not just throw an exception on developers machines, especially given the state of config schema in contrib (and probably even worse in custom code). I think it is mostly due to developers not being aware of the importance or even existence of config schema. One might naively think "my config doesn't need to be translated, therefore, I don't need a schema for it".
So if there were a warning all of a sudden, maybe people would look what it is about and fix it. Maybe we need to add a link to a documentation page about config schema.
But here is a attempt to get this back on track. I think we need schema validation, but I also think first we need to raise awareness of how important config schema is.
Comment #89
bircherOk I guess it should adhere to coding standards for people to review :D
Comment #91
chi commentedThe current change record is outdated.
Comment #92
chi commentedComment #93
bircherOh, of course both files need to have the same content... should have known.
We should probably debate the message if we agree to take this route.
Comment #94
chi commentedLooks good to me. I am using this approach #93 for a few years. It helped me to discover many config schema issues in custom code and contrib.
Comment #95
chi commentedThe message is a bit confusing. I know it comes from the exception but since it's now showed in admin UI can we improve wording somehow?
For people that are not familiar with Drupal Configuration system it could be hard understand what's wrong.
I expect many Drupal developers will get this message on their local hosts. So the CR should have some explanation of what configuration schema is and how to fix errors in it, probably with some links to the documentation on drupal.org.
Comment #103
bbralaUpdated the CR, updated the message to be more helpful and also show a link to the documentation. Tests seem green. Let's see if we can continue here.
Comment #104
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #105
bbralaRemoved new forbidden word "please" from the message.
Comment #106
smustgrave commented1 small comment but
Is the todo still needed?
Has the namespace been decided?
Comment #107
godotislateAdded a couple small grammar suggestions.
Comment #108
bbralaWe can decide the namespace, i think this placement is all good.
Comment #109
bbralaApplied suggestion for grammar and adjusted contructor.
Comment #110
smustgrave commented+1 from me.
Comment #111
godotislateNit: add
readonlyto the promoted properties. Otherwise can RTBC.Comment #112
bbralaYeah, might as well, good one.
Comment #113
godotislateThere are test failures. Might need rerunning?
Comment #114
smustgrave commentedRe-run seemed to do the trick. Believe all feedback has been addressed
Comment #115
alexpottThe CR is no longer correct as the class is not moving. I do think that the CR should exist - it should detail that by default if you use the development.services.yml you will can warnings when saving configuration that does not comply with schema. Once the CR is updated this can be set back to RTBC. The solution looks elegant and it's great that this emits warnings rather than errors.
Comment #116
bbralaCR has been updated.
Comment #117
borisson_CR looks great.
Comment #118
alexpottCommitted 733dc5f and pushed to 11.x. Thanks!