- Issue created by @phenaproxima
- πΊπΈUnited States phenaproxima Massachusetts
- πΊπΈUnited States phenaproxima Massachusetts
- Merge request !58Validate config that gets imported from modules or the recipe's config directory β (Open) created by phenaproxima
- Status changed to Needs review
7 months ago 6:54pm 15 November 2023 - πΊπΈUnited States phenaproxima Massachusetts
I think this is ready for initial review. It has test coverage and everything!
- Status changed to RTBC
7 months ago 2:51pm 20 November 2023 - π§πͺBelgium Wim Leers Ghent π§πͺπͺπΊ
RTBC per https://git.drupalcode.org/project/distributions_recipes/-/merge_request... β AFAICT this is a net improvement.
- Status changed to Needs work
7 months ago 4:15pm 20 November 2023 - Status changed to Needs review
7 months ago 5:45pm 20 November 2023 - πΊπΈUnited States phenaproxima Massachusetts
Back to review here; if it looks good then I think we might need to postpone this issue on #3390919: [PP-2] If a recipe fails to apply due to config validation errors, revert the site's config to its original state β . I tried to explain why in https://git.drupalcode.org/project/distributions_recipes/-/merge_request....
- Status changed to Postponed
7 months ago 6:09pm 20 November 2023 - πΊπΈUnited States phenaproxima Massachusetts
I discussed this with @alexpott. He confirmed that my understanding in https://git.drupalcode.org/project/distributions_recipes/-/merge_request... is correct.
We probably need to ultimately do something like this:
Do the current check (ensure dependencies look right beforehand), using
validateDependencies()
.
Create all the config, withcreateConfiguration()
.
Go back and callvalidate()
on all the config we just created. If any of it fails, throw the new ConfigValidationException, and let the recipe runner revert everything back to its pre-recipe state.Therefore, this issue is postponed on #3390919: [PP-2] If a recipe fails to apply due to config validation errors, revert the site's config to its original state β .
- π§πͺBelgium Wim Leers Ghent π§πͺπͺπΊ
I was wrong, you were right! π
Now eagerly following #3390919: If a recipe fails to apply due to config validation errors, revert the site's config to its original state β π
- π§πͺBelgium Wim Leers Ghent π§πͺπͺπΊ
One question though:
- Go back and call
validate()
on all the config we just created. If any of it fails, throw the new ConfigValidationException, and let the recipe runner revert everything back to its pre-recipe state.
We could already do that today, even without #3390919: If a recipe fails to apply due to config validation errors, revert the site's config to its original state β . But rather than an automatic revert, we'd have to tell the user something like "Either manually fix the configuration or revert both the code and the database to the previous state."
To @bircher's point in #3390919-23: If a recipe fails to apply due to config validation errors, revert the site's config to its original state β β we may need to support that anyway.
So AFAICT this is hard blocked, but it just make more sense to do the other issue first. Is my understanding corect?
- Go back and call
- πΊπΈUnited States phenaproxima Massachusetts
So AFAICT this is [not] hard blocked, but it just make more sense to do the other issue first. Is my understanding corect?
That's correct!
- Status changed to Needs work
6 months ago 3:16pm 8 December 2023 - π§πͺBelgium Wim Leers Ghent π§πͺπͺπΊ
Understanding this
So this is built on:
* 6cc95f1b6f5286b93198ef36f678a88005045d80 Make core dispatch config events for non-default collections.
aka π Config collections do not trigger configuration events consistently Fixed-
* 9270b7d97ab43e644942ff13d6548eec49f91934 Add checkpoints support
aka #3390919: [PP-1] If a recipe fails to apply due to config validation errors, revert the site's config to its original state β , but note that this is causing one of the PHPStan level 9 violations: https://git.drupalcode.org/project/distributions_recipes/-/merge_request...
Could you in the future please state precisely which commit you've applied from those issues? π
The other PHPStan level 9 error is https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iter... β not quite sure how to fix it.
Review
To review this, look at
git diff 9270b7d97ab43e644942ff13d6548eec49f91934
.Overall: very nice start! π
- I think the #1 thing to add is the most basic test coverage possible: a trivial config-only recipe that fails causes a validation error, and is then automatically reverted.
- Then subsequently, have a recipe FOO that depends upon another recipe BAR, and have BAR trigger a validation error, which should cause the end result to revert to the pre-FOO state, not the pre-BAR state.
- Next, add modules/themes to the mix that do not alter DB schema, but do install config of their own β to test that that too can be cleanly reverted.
- πΊπΈUnited States phenaproxima Massachusetts
This is also blocked by #3407956: [PP-1] Create a config storage checkpoint before applying a recipe, and clean it up afterwards β , which will alter the code in this MR.
- πΊπΈUnited States phenaproxima Massachusetts
I was able to manually test this and I have some confirmation that it does what we intend, based on the situation detailed in #3390919: Create a config storage backend that can set "checkpoints", recording the changes to config that happen in between them β ! Here's what I did:
git clone git@github.com:phenaproxima/recipe-test.git cd recipe-test composer i ./vendor/bin/drush si minimal ./vendor/bin/drush cex -y
Then, edit
web/recipes/gin-admin-experience/recipe.yml
thus:- Remove the entire
actions
section - Remove
help
from theinstall
list
Now, do this:
cd web php core/scripts/drupal recipe ./recipes/gin-admin-experience
You'll see something like this:
In InvalidConfigException.php line 21: Object(Drupal\Core\Config\Schema\Mapping).dependencies.module.0: Module 'help' is not installed. In RecipeConfigInstaller.php line 60: Object(Drupal\Core\Config\Schema\Mapping).dependencies.module.0: Module 'help' is not installed.
That's what we'd expect to see. But here's the proof that all changes were rolled back: if you run
../vendor/bin/drush cex
, it should tell you that there are no config changes!! - Remove the entire
- Assigned to Wim Leers
- Merge request !64Resolve #3401867 "Validate config post checkpointstorage" β (Open) created by Wim Leers
- π§πͺBelgium Wim Leers Ghent π§πͺπͺπΊ
Wim Leers β changed the visibility of the branch 3401867-validate-config-that to hidden.
- π§πͺBelgium Wim Leers Ghent π§πͺπͺπΊ
Wim Leers β changed the visibility of the branch 3401867-validate-config-post-checkpointstorage to hidden.
- π§πͺBelgium Wim Leers Ghent π§πͺπͺπΊ
Wim Leers β changed the visibility of the branch 3401867-validate-config-post-checkpointstorage to active.
- π§πͺBelgium Wim Leers Ghent π§πͺπͺπΊ
Closed/hid https://git.drupalcode.org/project/distributions_recipes/-/merge_request..., created https://git.drupalcode.org/project/distributions_recipes/-/merge_request... instead, because π Config collections do not trigger configuration events consistently Fixed and #3390919: Create a config storage backend that can set "checkpoints", recording the changes to config that happen in between them β have both landed.
(Also made sure the MR was created correctly this time, so now only 27 commits show up instead of Drupal core commits that we didn't do β MUCH easier to reviewπ)
- π§πͺBelgium Wim Leers Ghent π§πͺπͺπΊ
So we went from postponed on 2 to postponed on 0 β¦ but AFAICT #3407956: Create a config storage checkpoint before applying a recipe, and clean it up afterwards β is the new blocker here, because that's where we'll add the checkpointing first, without actually doing anything with it just yet.
- Status changed to Postponed
5 months ago 7:03pm 29 January 2024 - πΊπΈUnited States phenaproxima Massachusetts
I think we can say this is, in fact, postponed. It's hard-blocked by #3407956: Create a config storage checkpoint before applying a recipe β .
- Status changed to Needs work
5 months ago 12:57am 31 January 2024 - πΊπΈUnited States phenaproxima Massachusetts
Updated the issue summary to clarify what will actually happen if a recipe imports invalid config.
- Status changed to Needs review
5 months ago 3:03pm 2 February 2024 - Issue was unassigned.
- Status changed to Needs work
4 months ago 2:13pm 6 February 2024 - π§πͺBelgium Wim Leers Ghent π§πͺπͺπΊ
A small amount of MR simplification is possible and will make it easier to land this MR, so let's do that? π
- Status changed to Needs review
4 months ago 2:32pm 6 February 2024 - πΊπΈUnited States phenaproxima Massachusetts
I think all feedback thus far is addressed. Back to you!
- Status changed to RTBC
4 months ago 9:05am 7 February 2024 - π§πͺBelgium Wim Leers Ghent π§πͺπͺπΊ
Agreed, this looks great now! π€©
Overview of the changes:
- One exception is gone and is replaced by a more generic one β¦
- β¦ because the logic that triggered the original exception is no longer owned by Recipes, but by core's existing validation constraints π
- The
RecipeCommand
class'::boot()
became slightly more resilient β¦ - β¦ because now there is automatic rollback of a recipe whenever a config validation error is encountered when applying a recipe π
- All other changes are test coverage, which became quite a bit more complete now π
- First commit to issue fork.
- π¬π§United Kingdom alexpott πͺπΊπ
Removed the boot() changes. We need to handle container the container better in \Drupal\Core\Recipe\RecipeRunner::processRecipe too... - it's a hard problem. The solution is probably to pass the kernel object around but I think we should address all of this in one issue and not do anything piecemeal.
- π¬π§United Kingdom alexpott πͺπΊπ
Committed and pushed 21216ed8d00 to 11.x and 76055eeffe1 to 10.2.x. Thanks!
-
alexpott β
committed 76055eef on 10.2.x
Issue #3401867 by phenaproxima, Wim Leers, alexpott: Validate config...
-
alexpott β
committed 76055eef on 10.2.x
- Status changed to Fixed
4 months ago 10:42am 22 February 2024 -
alexpott β
committed 21216ed8 on 11.x
Issue #3401867 by phenaproxima, Wim Leers, alexpott: Validate config...
-
alexpott β
committed 21216ed8 on 11.x
-
alexpott β
committed 0292f8b8 on 10.2.x
Revert "Issue #3401867 by phenaproxima, Wim Leers, alexpott: Validate...
-
alexpott β
committed 0292f8b8 on 10.2.x
- 4683c884 committed on patch
Update recipe 10.2.x patch 0292f8b8 Revert "Issue #3401867 by...
- 4683c884 committed on patch
- π¬π§United Kingdom alexpott πͺπΊπ
This was reverted from the 10.2.x patch
Automatically closed - issue fixed for 2 weeks with no activity.