Problem/Motivation
Admin > Status > Reports lists entity mismatch on 8.x-1.x to 2.x upgrade.
Mismatched entity and/or field definitions
The following changes were detected in the entity type and field definitions.
Site Setting
- The Site Setting entity type needs to be updated.
- The Revision log message field needs to be installed.
- The Revision log message field needs to be uninstalled.
Steps to reproduce
- Set up standard install Drupal 10.3
- Install 8.x-1.x site settings & test sample data module
- Checkout 2.0.x branch
- Run drush updb
- Check Admin > Status > Reports
Proposed resolution
Update the post update hooks appropriately
Temporary solution, use Entity Updates module:
ddev composer require 'drupal/entity_update:^3.0'
ddev drush pm-enable entity_update
ddev drush upe site_setting_entity
ddev drush pm-uninstall entity_update
ddev composer remove drupal/entity_update
Remaining tasks
Merge request needed
User interface changes
N/A
API changes
N/A
Data model changes
N/A
Comments
Comment #3
scott_euser commentedTaking a look
Comment #5
scott_euser commentedShould work now with this patch; added better support for the range of fields that may or may not exist depending on the version you are updating from.
Comment #7
scott_euser commentedOkay in any case this does no harm. Feel free to reopen if it hasn't solved for you.
Comment #8
nagy.balint commentedHi!
I was wondering why the warning would stop the execution of the post update.
And so I updated the module and hoped that that will fix the issue.
But now I noticed that even with the latest version I get
entity_update module can fix it of course, but not sure why this happens, when it seems it did create the right tables for revision.
Maybe something was wrong on my system, but I reopen just in case anyone sees the same.
I tried to update from 1.x dev.
Comment #9
scott_euser commentedDoes this help at all revealing some other issue? https://drupal.stackexchange.com/a/307172
Comment #10
nagy.balint commentedNot much more information I am afraid.
I basically reload my db dump before the upgrade, do the upgrade rc4 and I get this:
Comment #11
nagy.balint commentedAh and the output of the updb
Comment #12
scott_euser commentedHmmm maybe revision log message has since had updates, that update hook is quite old. Perhaps it's setting the update to be into a destination state that is outdated and the expected state by core perhaps is now different.
Comment #13
scott_euser commentedUpdating title as per comment in #8
Comment #14
scott_euser commentedComment #15
nagy.balint commentedAs I see it is mainly following this change record: https://www.drupal.org/node/3034742
But something must be missing maybe a method call somewhere.
I'm using Drupal 10.3.1, not sure if the issue comes from that.
Comment #16
scott_euser commentedHmm but that has been the case for ages though. These two functions are attempting to do the manual process:
The challenge is keeping those two methods in sync indefinitely with a thing that is controlled partially by Core. That's my guess at least, perhaps something in Core has since changed to the revisionable table structure and making these post update functions needing a code change to match that. Ie, there must be some difference between a fresh install and an upgrade from 1,x for this to be flagged if I understand it right.
Comment #17
scott_euser commentedConfirmed I can reproduce this, steps added to card description
Comment #18
nagy.balint commentedHi!
I found a similar patch on drupal commerce.
I did the following test:
I installed commerce 2.39
I created a store and a test product.
Then I applied the patch from
https://git.drupalcode.org/project/commerce/-/merge_requests/243/diffs
This patch updates product entity to be revisionable.
And interestingly this did not cause mismatched entity for me, while the revision tab appeared on the entity.
But they organize the code differently, and they add the revision message log in an update hook (commerce_product_update_8213()) not in the post update.
Comment #21
scott_euser commentedOkay issue is there is meant to be an index name 'site_setting_entity__status_type' on table 'site_setting_entity_field_data' that is a mix of 'status', 'type', and 'id' but the index is missing when upgrading from 1x to 2x
Comment #22
scott_euser commentedAnd the other issue is the
revision_log_messagecolumn is missing from both site_setting_entity_field_data and site_setting_entity_field_data_revision tables.Comment #23
scott_euser commentedHmm yeah, its not in their
commerce_product_make_revisionable(), interesting!Comment #24
scott_euser commentedFor now at least I can see this sorts the issue for those who come across this:
Comment #25
nagy.balint commentedIt does however in that case one would need to run that module in production.
Comment #26
scott_euser commentedVery true; I am just not sure how to solve this myself (this feature was contributed by others in the first place). If someone can figure out how to solve it great!
Comment #27
nagy.balint commentedI think this might explain the issue:
https://www.drupal.org/project/sitewide_alert/issues/3194076#comment-139...
So the entity definition might be wrong
It should be "revision_log_message" = "revision_log_message",
There is a patch which renames it in that module, but it seems a bit long.
But then it is kind of wrong in the main entity definition as well.
Comment #28
nagy.balint commentedOr alternatively we can change the post update to
This removes the log_message issue.
Now we just have
The Site Setting entity type needs to be updated.
I added
But it is still there, so we still miss something from the main entity.
Comment #29
nagy.balint commentedMaybe it is just a matter of adding the status_type index to the site_setting_entity_field_data table, but ALTER ing it in won't work of course.
Comment #30
scott_euser commentedThanks! Very got spot!! Easiest is to make the update hook match existing working sites I think to avoid a bigger update needed to convert existing sites. Annoying that its another thing that doesn't match standard Drupal Core entities though :(
On status index just reading up on https://www.drupal.org/project/drupal/issues/3005447 now, hoping something in there helps
Comment #31
scott_euser commentedLooks like he solved it in https://www.drupal.org/project/commerce/issues/2907367, but got complicated it seems, going to see if I can do something with a schema alter to let SqlContentEntityStorageSchema help here
Comment #32
scott_euser commentedOkay no luck here yet and my daughter woke up early so my time is up for the morning.
Last thing I tried is pushed which does seem to get the tables to match but not recognised by the entity update manager.
Comment #33
nagy.balint commentedI think I got it.
You need to add
and also at the end where you added the index the following:
source: https://www.drupal.org/docs/drupal-apis/update-api/updating-database-sch...
This way it worked for me.
Comment #34
scott_euser commentedAmazing, thank you so much! Added an update test as well which fails to have an empty change list without your suggested code, but results in empty change list after the code addition, so that confirms it as well.
Comment #35
scott_euser commentedUpdating credits
Comment #36
nagy.balint commentedI see this "drupal.10.3-site-settings-8.x-1.x.php.gz" file in the commits, should that be there?
Comment #37
nagy.balint commentedThe part with $key_value = \Drupal::keyValue('entity.storage_schema.sql'); I think should be inside the if (!$index_exists) { part, as normally we would only want to set it if the index did not exist.
It won't cause any issues of course either way.
It works fine!
Comment #38
scott_euser commentedYeah the .gz file is a fixture for the automated test https://www.drupal.org/docs/drupal-apis/update-api/writing-automated-upd...
Okay will nest it inside the index check, good point (probably no harm yeah but better to be safe).
Thanks!
Comment #40
scott_euser commentedThanks very much for your help with this! Was a real head scratcher
Comment #41
nagy.balint commentedSorry to reopen again,
but there is one more issue, that the revision UI is not enabled, while it is part of the entity definition.
But even if I add it to the post update hook:
It does not want to show up, and so I cant actually create a new revision in this case.
Not sure if I am missing something.
Comment #42
scott_euser commentedYou'd just need to disable the 'Hide advanced options' from /admin/config/site-settings/config. By default trying to keep the UI very simple like 1.x. Lots of features in over the years, but default should still be simplest case which would typically be labels/header/footer settings/etc where revisions are probably not necessary. If you want something more there, maybe a separate issue as separate feature request?
Comment #43
nagy.balint commentedNice! Thanks!