Problem/Motivation
block_content.post_update.php has this code:
\Drupal::classResolver(ConfigEntityUpdater::class)->update($sandbox, 'view', function ($view) use ($table) {
// ...fun stuff!
});
The problem is that, if Views is not installed, this fails with an "undefined entity type" exception. The config entity updater assumes (and understandably so) that the entity type being updated, well, exists.
This bug also appears in other post-update functions in core:
- taxonomy_post_update_handle_publishing_status_addition_in_views()
- views_post_update_exposed_filter_blocks_label_display()
- content_moderation_post_update_views_field_plugin_id()
- ...others? (hopefully not)
I'm also nominating this rather embarrassing bug for backport to 8.7.x, since it is present there as well.
Proposed resolution
Post-update functions should validate their expectations prior to using the config entity updater.
Remaining tasks
Write a failing test and fix it, then document that ConfigEntityUpdater expects you to mind your P's and Q's before you use it.
User interface changes
None.
API changes
None.
Data model changes
None.
Release notes snippet
None.
Comment | File | Size | Author |
---|---|---|---|
#24 | 3065663-24--8.7.x.patch | 7.31 KB | phenaproxima |
#20 | interdiff-3065663-16-20.txt | 4.24 KB | phenaproxima |
#20 | 3065663-20.patch | 9.07 KB | phenaproxima |
#16 | interdiff-3065663-13-16.txt | 994 bytes | phenaproxima |
#16 | 3065663-16.patch | 9.11 KB | phenaproxima |
Comments
Comment #2
phenaproximaHere's a fail patch...I'm not sure what the proper fix would be.
Comment #3
phenaproximaThis is blocking work on Panelizer; see #3065652: Fix failing tests.
Comment #4
phenaproximaTurns out that the Taxonomy module also suffers from this problem; see
taxonomy_post_update_handle_publishing_status_addition_in_views()
. It makes me wonder if we shouldn't fix this in ConfigEntityUpdater, rather than in the calling code.If we don't fix it there, then I need to expand the scope of this issue because I can't get the test to pass unless I fix the problem everywhere it occurs (which is at least two places so far, but there could be others).
Comment #5
phenaproximaTagging for framework manager input.
Comment #7
phenaproximaThis should look Christmas-ey.
I discussed this briefly with @alexpott on Slack and we decided that the fixes should be made in the update functions themselves, since "the update should handle its expectations". So, in order to get the test to pass, I had to fix the Taxonomy update function too. I'm re-titling this issue and changing the component, since this is no longer confined to the block_content module only.
Comment #8
phenaproximaFixing the issue title.
Comment #9
alexpottNice sleuthing @phenaproxima.
I'm not sure that ConfigEntityUpdater should check this because it's likely to hide other problems - for example an incorrect entity type ID. So I think we should do \Drupal::moduleHandler()->moduleExists() checks in the update hook.
So +1 on expanding the scope.
There's also:
content_moderation_post_update_views_field_plugin_id() - needs a views module check
views_post_update_exposed_filter_blocks_label_display() - needs a block module check
I think we should add some documentation to \Drupal\Core\Config\Entity\ConfigEntityUpdater() that it is the responsibility of the update hook to check that the entity type provider is installed. We could even add this to the example code.
Comment #10
phenaproximaRe-titling to take the content_moderation and views post-update hooks into account.
Comment #11
phenaproximaFine-tuning that.
Comment #12
phenaproximaComment #13
phenaproximaOK, I think this will be green. I added tests for each of the offending post-update functions.
Comment #14
tim.plunkettMy first thought when reading this patch is that the moduleExists check is not exactly what we care about. More correct would be
Which then begs the question, why not move that check into ConfigEntityUpdater itself?
Comment #16
phenaproximaOkay, this should fix that one failure.
Comment #17
alexpottre #14 my reasoning for going this way is because making the change in ConfigEntityUpdater makes the code susceptible to silent failure when you get the string identifier incorrect. #14 is the exact opposite of the direction already taken in the class which does...
This one is tricky... because both ways are can cause some annoyance. But I think failing when you get an ID incorrect is better.
Comment #18
Wim LeersHow does this test that updates are bypassed?
Comment #19
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedThe only feedback I have is that this comment (and the others in similar places) is not really accurate. We're not testing that the update function is bypassed, we're just testing that it doesn't fail if the module/entity type is not available :)
At least to me, "bypassed" means that we'd have an assertion to check that the function was not executed at all, which is not the case here.
As for the module vs. entity type check discussion from #14 / #17, I can't say I have any preference, so I'll trust @alexpott's feeling :)
Comment #20
phenaproximaGood feedback, thank you! How's this?
Comment #21
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedMuch better! :D
Comment #23
larowlanCommitted 24d99ff and pushed to 8.8.x. Thanks!
Doesn't apply cleanly to 8.7.x
Comment #24
phenaproximaThis should apply cleanly to 8.7.x.
Comment #25
phenaproximaBack to RTBC since this is a simple reroll.
Comment #26
alexpottCommitted 7ee5e1d and pushed to 8.7.x. Thanks!
Comment #28
alexpott