Background: If table names are too long then Drupal seems to shorten them, for example (MySQL in my case):
simple_mega_menu_revision__field_mm_embedded_view
becomes
simple_mega_menu_r__67fa896f01
In that case the update breaks with a message:
Table simple_mega_menu_revision__field_mm_embedded_view does not exist...
So the viewsreference_update_8103 should also make that transformation. Sadly I could not find out where that happens and by which function.
For my case I hacked a workaround into the update:
if($table == 'simple_mega_menu_revision__field_mm_embedded_view'){
$table = 'simple_mega_menu_r__67fa896f01';
}
but that was just a quickfix. Does somebody know where that shortening happens?
| Comment | File | Size | Author |
|---|---|---|---|
| #41 | interdiff-37-41.txt | 2.09 KB | tmanhollan |
| #41 | 2925609-41.patch | 183.28 KB | tmanhollan |
| #37 | 2925609-37.patch | 183.28 KB | tobiasb |
| #29 | 2925609-29.patch | 163.6 KB | seanb |
| #29 | interdiff-20-29.txt | 13.65 KB | seanb |
Issue fork viewsreference-2925609
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
seanbThat might be
Drupal\Core\Entity\Sql\DefaultTableMapping::generateFieldTableName(). Could you maybe test this and provide a patch?Comment #3
anybodyYeah that's it!
https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21...
So the table name should be run through it to fix this. But it is protected so there must be a correct way to handle the schema requests. I have no Idea to be honest.
Comment #4
seanbYou should probably try
Drupal\Core\Entity\Sql\DefaultTableMapping::getDedicatedDataTableName()and/orDrupal\Core\Entity\Sql\DefaultTableMapping::getDedicatedRevisionTableName().Comment #5
j.cowher commentedI've taken a stab at a patch for this. Works in my Drupal 8.5.1 environment.
Comment #6
j.cowher commentedLast patch file was incorrectly formatted. Please use this one instead.
Comment #7
j.cowher commentedThere were still some issues in the last patch. Adding back in the calls to the entity update manager.
Comment #8
juves commentedShould I apply the last patch if I already applied the previous one with composer? Or should I remove it first (how)?
UPD: repatched.
Comment #9
seanbThe code for this is pretty complex, so it would really help of more people could test the patch and confirms it solves the issue!
Comment #10
m@ster commentedthanks, patch save me a lot of time for upgrading!
Comment #11
sonameu commentedPatch works as intended . Thanks a lot
Comment #12
tobiasbI do not want create a new issue for this small changes. The migration process overrides existing data, with this changes we merge title/argument into data.
Comment #13
tobiasboh the patch from #7 contains a PATCHES.txt ;-)
Comment #14
tuthanh commented#13 let the update process go through.
But all of existing views reference paragraph data is gone with it.
Comment #15
tobiasbComment #16
tobiasbI will work on a test for this db upgrade thing.
Comment #17
joshua.boltz commentedThis patch worked great! I just updated to the 2.0 version of this module, because I needed to update in preparations for jumping up to D9.
I totally hit the base table not found error during database updates, but with this patch, I no longer get the errors during updb, and fields using views references appear to be working just fine and didn't notice any issues.
I'm not sure about #14, because in my case, the views reference data is maintained during the upgrade and all is seemingly working fine.
Comment #18
tobiasbThe update hook test did not work locally, because of a undefined bundles key in $field_map, but perhaps here. :D
Tests are not enabled? We are lost. :D
Comment #19
tobiasbComment #20
tobiasbFixed the undefined bundles key. (\Drupal\Core\Entity\EntityFieldManagerInterface::getFieldMapByFieldType)
Added config schema for successfully test. #2957529: Implement configuration schema for Views reference field storage+settings and widget+formatter
Comment #21
bwoods commentedI was also successful with #13. Before running DB updates, I made a copy of the one paragraph field table. After the DB update, I was able to export the table and import back in, and the structure was intact. I was a little confused at first that this particular field didn't also have a revisions table, but I guess that is not necessary for this type of field.
Comment #22
ibullock#20 worked for me, though I still did get one warning in the update:
Invalid argument supplied for foreach() better_exposed_filters.install:24Comment #23
ibullockFollowing up because I had issues with #20 where the supplied schema caused the "enabled settings" to fail to save properly. The values should be strings for them, currently only Pagination and Arguments will work otherwise. These settings are simple key/value pairs for the setting names and not their stored data (ie the number of items to show for "limit").
Comment #24
socialnicheguru commentedIs this, b/tests/fixtures/update/drupal-8.9.6.viewsreference-8.x-1.4.php.gz, needed from the last patch in #20
Comment #25
tobiasb@SocialNicheGuru
For the test yes.
Comment #26
banoodle commentedI have this problem and patch #20 allowed the database update to succeed where before it was failing.
I'm not sure if this is an issue related to this patch or if this is a separate issue, but I am getting these warnings now when saving a node with a views reference field (although the node and field data is saved correctly)...
Comment #28
seanbYay, got the tests to run. Thanks so much for the work on this. It would be great to get this in, I think this is the most important stable blocker at the moment.
Comment #29
seanbHere is a first update simply fixing the PHPCS errors in #20.
Comment #30
seanbLocally I'm getting a different error than DrupalCI:
Don't have the time to dig deeper at the moment, but hopefully, someone else can continue now we have the tests running!
Comment #32
tobiasbData can be empty (NULL) therefore I added a check and defaulted the value to empty array.
Also I created a new dump with 2 revision.
+ Some more asserts.
Comment #33
tobiasbTo test the scope I added also a field to a term.
Comment #34
tobiasbtest only patch.
Comment #35
tobiasbLets skip the test for D10.
Comment #37
tobiasbCoding standards.
Comment #38
dasginganinjaOn a _quick_ passthrough of this code I noticed that the ${var} syntax is being used in strings. PHP 8.2 doesn't like that ;)
Perhaps consider using sprintf to prepare the table/column names?
Comment #39
summit commentedHi, could you give a solution for this in code please? Thanks!
Comment #40
seanbGreat job on the tests, thanks! I think it would be nice to fix #38 as well. After that, it would really help to a bit more people to test this. But since this is a stable blocker I would really like to get this in asap.
Comment #41
tmanhollan commented#37 worked for me. Here's an updated version that addresses #38 by changing "${field_name}_..." to "{$field_name}_...".
Comment #42
sleitner commented+1 RTBC for patch #41
Comment #43
robloachSharing that the patch at #41 has worked here too. Thanks so much for the push!
Comment #45
seanbFinally got around to commit it. Thanks everyone for your hard work! ❤️
This is a great step towards getting 2.x stable!
Comment #47
grevil commentedWe forgot to include removing all unchecked viewsreference "plugin_types", "preselect_views" and "enabled_settings" field settings.
Before this patch, we had no schema definition for "plugin_types", "preselect_views" and "enabled_settings" AND no fieldSettingsFormValidate() method, which simply removes all unchecked setting values before form submission. So the module used to save both unchecked and checked field settings in config. If the value was checked, it saved the name of the value as a string (e.g. page:page) or if it was uncheckd as "0" (e.g. page: 0).
After this patch, the empty values are not getting saved anymore, but they still exist in config if not manually resaved. And since "viewsreference.plugin_types" and "preselect_views" (also "enabled_settings" now through #3402036: Configuration schema for "Enable extra settings" (title,pagination,...) incorrect), are defined as sequences of strings, but the old implicit schema definition for an unchecked value was integer, the following error will appear using config_inspector:
Here is an exported config as an example, showing the old unchecked values still saved:
I will create a follow-up issue for this.
Comment #48
grevil commentedDone, see here: #3445081: Add missing update hook for adjusting viewsreference field settings.