Problem/Motivation
Modules can add base fields to entity types using hook_entity_base_field_info(). Entity displays that use these fields don't have a dependency on these modules and on uninstallation of the module that provides them, the base fields are not properly cleaned up.
This was discovered in #2850973: ConfigEntityInterface::onDependencyRemoval() called with incorrect dependency list and is relevant to the uninstall of the scheduler module.
This is a major issue because it is a data integrity issue. Entity displays have configuration for base fields that no longer exist.
Proposed resolution
Add dependency in \Drupal\Core\Entity\EntityDisplayBase::calculateDependencies() and remove field \Drupal\Core\Entity\EntityDisplayBase::onDependencyRemoval() on module uninstall.
Remaining tasks
Needs tests
Needs upgrade path
User interface changes
None
API changes
None
Data model changes
New dependencies information in entity displays.
| Comment | File | Size | Author |
|---|---|---|---|
| #29 | 2924256-nr-bot.txt | 132 bytes | needs-review-queue-bot |
| #16 | 2924256-16.patch | 207.95 KB | alexpott |
| #16 | 15-16-interdiff.txt | 1.66 KB | alexpott |
Comments
Comment #2
alexpottHe's a bug fix and test for it. Now to write the upgrade path :(
Comment #3
chr.fritschSince this is a major bug, shouldn't it go into 8.4.x?
Comment #4
alexpott@chr.fritsch well there's going to be an upgrade path and generally we try not to add upgrade paths to patch releases.
Comment #6
alexpottAh I see - we don't need to add a dependency when the module that provides the base field is the same one that provides the entity type. This is because that is already taken care of by
And therefore the module will be in the dependency chain and is not worth adding again.
Patch attached also has the start of some work on the upgrade path tests...
Comment #9
alexpottHere's an update path test. New database needed because there are other updates like system_post_update_add_region_to_entity_displays() that would do the necessary saves to running with an old database is not good.
Interdiff doesn't contain the dumped db because it's not that helpful unless you can decompress stuff just by looking at it :)
Comment #10
amateescu commentedPatch is looking pretty good, here's a review:
"is provider" -> "is provided" ;)
Let's also mentioned the class name, not just the generic method name :)
This is not really useful since it doesn't do any assertion that a dependency has been added, so we need an assertion before running the updates on a set of dependencies and another assertion after the update process to check that the set of dependencies has been updated.
How about renaming this to
testBaseFieldDependencies()?How about using an update fixture that makes the system act like
system_post_update_add_region_to_entity_displays()already ran instead of providing yet another db dump :)You can find an example where we're already doing this in
core/modules/hal/tests/fixtures/update/drupal-8.rest-hal_update_8301.php.Comment #11
alexpottThanks for the review @amateescu
Run the update gz - it's not just about the updates that have run - the gzip also has entity_test and entity_test_extra installed. It has state to make \entity_test_extra_entity_base_field_info() actually work. It has entity displays (both form and view) for the entity_test entity type configured and it has the necessary entity updates run. To me that's enough to just a dump. I think maybe we should always add a dump for each minor release and it would be awesome if there was some tool that would help use make partial files like core/modules/hal/tests/fixtures/update/drupal-8.rest-hal_update_8301.php because at the moment the process seems very fragile and prone to making slightly sites fake sites as it is easy to miss something from a partial.
Comment #12
amateescu commentedOhh, right, I missed the interdiff from #9. Those assertions look exactly like what I would expect from this test :)
I don't think we should have this dump specific to version 8.4.2. I discussed this scenario with @catch some time ago and the outcome of that discussion was that we should try to allow upgrades across multiple minor releases at a time (directly from 8.1.x to 8.4.0 for example) on a best-effort basis, meaning that we can't guarantee that it will work but we also should *not* actively prevent that upgrade from working.
In our case, the bug that we're fixing here was not introduced in 8.4.2, it probably exists before 8.0.0 so the dump that we should be using is one that has 8.0.0 (maybe rc1 even) and uses the standard profile, because chances are that you can easily find an existing form/view display that is missing dependencies of a base field which should be fixed by this update.
The reason I'm not keen on adding db dump so easily because they're essentially a black box, no one but the person who created them actually knows what they contain (sometimes even that person forgets :D), so they are realistically one-off blobs of data that we keep piling on without much enticement for re-usability :)
Comment #13
alexpottI don't think so. This is because you only get extra dependencies when base fields are added by an another module than the one that provides the entity as the entity display already has a dependency on the entity type / bundle.
Comment #14
alexpottI thought maybe I spoke to quick re #13 because of things like path_entity_base_field_info() but actually the entity displays already have a dependency on path because the field type it is provided by path. So the situation is we need hook_entity_base_field_info() where the added fields are not provided by the same module and I don't think we have that in any core install - as example in real code would be content_moderation_entity_base_field_info() but no profile is configured to use that module yet. Hmmm... that said maybe content_translation_entity_base_field_info() might cause this. Maybe drupal-8.filled.standard.php.gz has something for us. That said I'm not really sure how this actually gets us around the black box issue because drupal-8.filled.standard.php.gz is an unknown too really and just hacking the run updates to not call system_post_update_add_region_to_entity_displays() puts the system in a state it could never actually be in.
Comment #15
alexpottUnfortunately there are no entity view displays in the Drupal 8 filled standard dump so that's not an option. So to open up the black box I've added documentation to the test to explain exactly what is in the dump and how it was made.
Comment #16
alexpottSlightly better comment.
Comment #20
jonathan1055 commentedThanks for your work on this. I can't recall whether I did any manual testing when the issue was first started, but I will check it again.
I re-queued the patch in #16 but it needs a re-roll.
I'm trying to sort out #3038746: Remove deprecated EntityDefinitionUpdateManagerInterface::applyUpdates() from hook_install and hook_uninstall and having the fields remain after uninstall is making the task harder to test.
Comment #21
jonathan1055 commentedI have manually re-tested the patch in #16 on 8.5.11 (just the first two files, not the addition to testing) and it appiles OK and does the job required. After uninstalling the module the two base fields are immediately removed from core.entity_form_display.node.article.default (checked using config inspector). The fields are also removed from the content type 'manage form display' tab.
I have not tested on 8.6 or 8.7 as the patch was created for 8.5.
Comment #29
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.