Problem/Motivation
system.performance has 4 property path that are not yet validatable:
./vendor/bin/drush config:inspect --filter-keys=system.performance --detail --list-constraints
➜ 🤖 Analyzing…
Legend for Data:
✅❓ → Correct primitive type, detailed validation impossible.
✅✅ → Correct primitive type, passed all validation constraints.
----------------------------------------------- --------- ------------- ------ ------------------------------------------
Key Status Validatable Data Validation constraints
----------------------------------------------- --------- ------------- ------ ------------------------------------------
system.performance Correct 76% ✅❓ ValidKeys: '<infer>'
system.performance: Correct Validatable ✅✅ ValidKeys: '<infer>'
system.performance:_core Correct Validatable ✅✅ ValidKeys:
- default_config_hash
system.performance:_core.default_config_hash Correct Validatable ✅✅ NotNull: { }
Regex: '/^[a-zA-Z0-9\-_]+$/'
Length: 43
↣ PrimitiveType: { }
system.performance:cache Correct Validatable ✅✅ ValidKeys: '<infer>'
system.performance:cache.page Correct Validatable ✅✅ ValidKeys: '<infer>'
system.performance:cache.page.max_age Correct NOT ✅❓ ⚠️ @todo Add validation constraints here
system.performance:css Correct Validatable ✅✅ ValidKeys: '<infer>'
system.performance:css.gzip Correct Validatable ✅✅ ↣ PrimitiveType: { }
system.performance:css.preprocess Correct Validatable ✅✅ ↣ PrimitiveType: { }
system.performance:fast_404 Correct Validatable ✅✅ ValidKeys: '<infer>'
system.performance:fast_404.enabled Correct Validatable ✅✅ ↣ PrimitiveType: { }
system.performance:fast_404.exclude_paths Correct NOT ✅❓ ⚠️ @todo Add validation constraints here
system.performance:fast_404.html Correct NOT ✅❓ ⚠️ @todo Add validation constraints here
system.performance:fast_404.paths Correct NOT ✅❓ ⚠️ @todo Add validation constraints here
system.performance:js Correct Validatable ✅✅ ValidKeys: '<infer>'
system.performance:js.gzip Correct Validatable ✅✅ ↣ PrimitiveType: { }
system.performance:js.preprocess Correct Validatable ✅✅ ↣ PrimitiveType: { }
----------------------------------------------- --------- ------------- ------ ------------------------------------------
Steps to reproduce
- Get a local git clone of Drupal core
10.3.x.
composer require drupal/config_inspector — or manually install https://www.drupal.org/project/config_inspector/releases/2.1.5 or newer (which supports Drupal 11!)
composer require drush/drush
vendor/bin/drush config:inspect --filter-keys=system.performance --detail --list-constraints
Proposed resolution
Add validation constraints to:
system.performance:cache.page.max_age
system.performance:fast_404.exclude_paths
system.performance:fast_404.html
system.performance:fast_404.paths
For examples, search *.schema.yml files for the string constraints: 😊
Reach out to @borisson_ or @wimleers in the #distributions-and-recipes.
Remaining tasks
User interface changes
None.
API changes
Data model changes
More validation 🚀
Release notes snippet
None.
Comments
Comment #4
narendrarComment #5
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. 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 #6
narendrarComment #7
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. 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 #8
narendrarComment #9
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. 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 #10
phenaproximaComment #11
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. 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 #12
wim leersThe changes to the kernel test are out of scope. The "fix" is wrong.
Comment #13
phenaproximaComment #14
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. 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 #15
phenaproximaComment #16
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. 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 #17
phenaproximaDear bot, get lost.
Comment #18
wim leersDivisibleByinstead ofChoice.IMHO it should be done here, not elsewhere, because none of the existing uses of the
Choiceconstraint in Drupal core so far are using it to restrict it to a list of integers. In principle, there's nothing wrong with that, but it'll be very likely that values specified in config by hand will be considered incorrect. The "multiple of 60" rule that @phenaproxima proposes is much more elegant: it's lenient to allow any number, as long as it's with a granularity of 1 minute. That seems much better!Comment #19
phenaproximaComment #20
wim leers11.x.Comment #25
mikelutzOpened a new MR against 11.x, and added a constraint to validate whether a string is valid regex.
Comment #26
smustgrave commentedCan the MR be rebased? Believe the errors may be related to broken HEAD from the other day.
Comment #27
mikelutzComment #28
mikelutzNW for Phenaproxima's comments.
Comment #29
mikelutzThat all sounds good to me. I also set 'regex' as a schema type so we don't have to add the constraint anywhere we might need to use it in the future.
As a side note, it seems weird to me that 'exclude paths' can't be empty/null, but I checked the code, and fast404 just doesn't do anything unless you exclude *something*. Seems like that could be adjusted, but out of scope here.
All feedback addressed. back to NR.
Comment #30
mikelutzThe failing test seems to be broken on HEAD, will rebase once it's fixed.
Comment #31
mikelutzRebased now that #3448036: InstallerTranslationExistingFileTest fails on 11.x branch is in. Tests should pass now.
Comment #32
borisson_I think this looks great, I agree that both html and regex being new types is a good idea for reusability. We should create change records for both of those new types.
Comment #33
smustgrave commentedAgreed on the CR.
Eventually would love if we could update the cheat sheet on https://www.drupal.org/docs/drupal-apis/configuration-api/configuration-... or start a new one.
Comment #34
narendrarComment #35
smustgrave commentedCR's look good. I really like the sections "How to use?" even though pretty straightforward it's a nice touch.
Thanks!
Comment #36
catchDon't really agree with max age being limited to multiples of 60, left a comment on the MR.
Comment #37
mikelutzThe latest push makes the change I recommended above, constraining the value to an integer between 1 and 3156000 and reconfiguring the form to use a number field with the same constraints. I didn't see any specific tests around this form to adjust, but there might be a functional Javascript test somewhere that will need to be adjusted.
Comment #38
mikelutzReverted the form changes and moved them to a follow-up #3451592: Improve UX of system performance form max-age form input to determine how best to improve the form UX
Also reverted the changes to ConstraintManager that exposed DivisibleBy as we are no longer going to use it here.
Thanks to @catch and @phenaproxima for the slack discussion. Back to NR
Comment #39
smustgrave commentedChecked the CR and both read fine. "Generally speaking:" like those sections
Ran test-only feature and got https://git.drupalcode.org/issue/drupal-3437608/-/jobs/1740193 so definitely shows extensive test coverage.
Checking MR appear all feedback has been resolved.
Applied to 11.x with config inspector installed
Comment #40
wim leersLGTM!
Comment #41
alexpottI've added a couple of comments to the MR - minor test related stuff. Otherwise this looks great.
Comment #42
narendrarFeedback addressed.
Comment #43
borisson_Back to rtbc now that the remarks have been fixed.
Comment #44
alexpottI think we need to think a bit more about HTML validation and what an html type means. Plus we have an issue with adding a new code dependency to the Utility component.
Comment #45
phenaproximaThat makes sense.
IMHO, we should be looking at this as a snippet of HTML, rather than a full page. What would be a reasonable way of validating that, if we can't use a parser?
I also agree that we don't want to add accidental cross-component dependencies, so this probably needs some refactoring. Maybe a whole new constraint to confirm that something is a valid HTML snippet?
Comment #46
mikelutzI'm going to move it to a full fledged constraint in Core/Validation to solve the dependency issue. To make it work for both snippets and full pages, I think we can have the constraint just wrap snippets in
"<!DOCTYPE html><html><head></head><body>" .. "</body></html>". We could either define whether to do so in an argument to the constraint, or try to autodetect, but I'm going with a constraint argument that defaults to snippet because the schema would want to decide which it allows. The fast_404 html here would want a full page and want to reject a snippet so I don't see autodetecting being practical.(Ironically, I was resurrecting #2852463: Create a trait and base class to implement \Drupal\Component\Plugin\ConfigurableInterface the other day and I realized the we nearly did the same intercomponent dependency in the patch we committed and reverted all those years ago. We were going to call Component\Utility\NestedArray from Component\Plugin and didn't notice)
Comment #47
mikelutzComment #48
phenaproximaFound a lot of small things I think could be improved. But in general I agree with the approach here and the usefulness of these new constraints.
Comment #50
bbralaDid a codestyle fix and a rebase, since it was behind so much. That will create issues with lint jobs.
Comment #51
bbralaProcessed all the comments, rebased, updated the CR's. Think this is ready.
Comment #52
borisson_I have one tiny nitpick on the comment, but I think @bbrala is right, this looks ready.
Comment #53
alexpottSome review comments to address. Two I would have fixed on commit. One which needs a little bit of thought hence back to needs work.
Comment #54
borisson_The suggestion in #53 makes complete sense to me, it's now updated so moving it back to rtbc.
Comment #55
bbralaThe failure is unrelated afaik, and it succeeds locally.
Comment #56
alexpottI've tried to find out in the issue comments but I can't see where it is decided but I'm really surprised by the schema changing when the fast 404 is enabled or disabled. This is not a regular thing. Normally you can disable something and leave the other config in place. I'm not sure why the complexity has been introduced. Setting back to needs review to get an answer.
Comment #57
bbralaHmm, the pattern here is indeed old. Didnt notice that. Used it in the other issues to just use $options instead. Can work with that. Wonder though if this pattern is inconsistent in other places also, would be nice to have it all the same.
The fast404 is indeed rather unique, i'll dig a bit, there is another branch that was closed, that split was committed bu phenaproxima. I can imagine why, where those fields are really only relevant when the configuration is set. But looking at the other schema commits it is not really standard. I'll dive into it, see if i can give you an awnser from the history here (or somewhere else0.
Comment #58
bbralaThis is what i found out. It was committed by @phenaproxima https://git.drupalcode.org/issue/drupal-3437608/-/commit/faea4b55fedea2e...
I did find some other examples (yay):
Where depending on the value is does
Oh and another one!
editor.image_upload_settings.*:So perhaps the idea was, lets only require those field when fast404 is enabled. But that could mean we should also tell the schema what the data should be if it is not enabled? Maybe something like same, but nullable. Then you don't really need to fill the keys.
Comment #59
bbralaSimplified and adressed feedback.
Comment #60
bbralaHmm, I've been doing some things to see if i can double check how this works. I would say we should be able to not fill the other fields when disabled, which is kinda important. But after trying a few different iterations it seems it might now validate if i try to handle enabled and disabled properly.
I'll dive into this a little more and make sure i can prove validation works as expected when disabled. We could also still choose to first always validate the fields. But i'll see if i can proove this first.
Codedump for later
Fast404Test.php
system.schema.yml
Comment #61
bbralaOk, i've tested the results.
When defining the .0 state also we can validate the values, but allow them to be empty. This way we know for sure the config is valid, but if the values are not set and we enable we get an error.
For now the test is in the existing test, which although efficient, does seem as the wrong place, so we need to move that. Also i would prefer if we do some tests for the different possible combinations, showing it validates the fields when set, even when disabled.
Comment #62
bbralaHmm, maybe the placement for the test is not really wrong, i'll keep it there for now.
Comment #63
bbralaTest fail seems to be unrelated, nightwatch is fun.
Comment #64
bbralaAh, after rerun they are gone.
Comment #65
borisson_There's an open question on the MR, can we answer that?
Comment #66
bbralaAwnsered. :)
Comment #67
borisson_This looks great, thanks for answering that question.
Comment #68
longwaveTwo nits, I think "fragment" is a more recognisable and well-defined term than "snippet".