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?

Command icon 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

Anybody created an issue. See original summary.

seanb’s picture

That might be Drupal\Core\Entity\Sql\DefaultTableMapping::generateFieldTableName(). Could you maybe test this and provide a patch?

anybody’s picture

Yeah 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.

seanb’s picture

You should probably try Drupal\Core\Entity\Sql\DefaultTableMapping::getDedicatedDataTableName() and/or Drupal\Core\Entity\Sql\DefaultTableMapping::getDedicatedRevisionTableName().

j.cowher’s picture

Status: Active » Needs review
StatusFileSize
new12.24 KB

I've taken a stab at a patch for this. Works in my Drupal 8.5.1 environment.

j.cowher’s picture

StatusFileSize
new14.2 KB

Last patch file was incorrectly formatted. Please use this one instead.

j.cowher’s picture

StatusFileSize
new15.21 KB

There were still some issues in the last patch. Adding back in the calls to the entity update manager.

juves’s picture

Should I apply the last patch if I already applied the previous one with composer? Or should I remove it first (how)?
UPD: repatched.

seanb’s picture

The code for this is pretty complex, so it would really help of more people could test the patch and confirms it solves the issue!

m@ster’s picture

thanks, patch save me a lot of time for upgrading!

sonameu’s picture

Patch works as intended . Thanks a lot

tobiasb’s picture

StatusFileSize
new15.33 KB
new1.17 KB

I 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.

tobiasb’s picture

StatusFileSize
new14.97 KB
new373 bytes

oh the patch from #7 contains a PATCHES.txt ;-)

tuthanh’s picture

#13 let the update process go through.

But all of existing views reference paragraph data is gone with it.

tobiasb’s picture

Issue tags: +Needs tests
tobiasb’s picture

Assigned: Unassigned » tobiasb

I will work on a test for this db upgrade thing.

joshua.boltz’s picture

This 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.

tobiasb’s picture

The 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

tobiasb’s picture

Fixed 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

bwoods’s picture

I 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.

ibullock’s picture

#20 worked for me, though I still did get one warning in the update:

Invalid argument supplied for foreach() better_exposed_filters.install:24

ibullock’s picture

Following 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").

socialnicheguru’s picture

Is this, b/tests/fixtures/update/drupal-8.9.6.viewsreference-8.x-1.4.php.gz, needed from the last patch in #20

tobiasb’s picture

@SocialNicheGuru

For the test yes.

banoodle’s picture

I 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)...

Warning: Undefined array key "data" in Drupal\viewsreference\Plugin\Field\FieldType\ViewsReferenceItem->setValue() (line 97 of modules/contrib/viewsreference/src/Plugin/Field/FieldType/ViewsReferenceItem.php).
Deprecated function: unserialize(): Passing null to parameter #1 ($data) of type string is deprecated in Drupal\viewsreference\Plugin\Field\FieldType\ViewsReferenceItem->setValue() (line 97 of modules/contrib/viewsreference/src/Plugin/Field/FieldType/ViewsReferenceItem.php).

Only local images are allowed.

Status: Needs review » Needs work
seanb’s picture

Yay, 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.

seanb’s picture

StatusFileSize
new13.65 KB
new163.6 KB

Here is a first update simply fixing the PHPCS errors in #20.

seanb’s picture

Status: Needs work » Needs review

Locally I'm getting a different error than DrupalCI:

There should be no errors in configuration 'core.entity_view_display.node.page.default'. Errors:
Schema key core.entity_view_display.node.page.default:content.field_viewsreference.settings.plugin_types.default failed with: variable type is integer but applied schema class is Drupal\Core\TypedData\Plugin\DataType\StringData
Schema key core.entity_view_display.node.page.default:content.field_viewsreference.settings.plugin_types.page failed with: variable type is integer but applied schema class is Drupal\Core\TypedData\Plugin\DataType\StringData
Schema key core.entity_view_display.node.page.default:content.field_viewsreference.settings.plugin_types.feed failed with: variable type is integer but applied schema class is Drupal\Core\TypedData\Plugin\DataType\StringData

Don't have the time to dig deeper at the moment, but hopefully, someone else can continue now we have the tests running!

Status: Needs review » Needs work

The last submitted patch, 29: 2925609-29.patch, failed testing. View results

tobiasb’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new173.21 KB
new295.79 KB

Data 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.

tobiasb’s picture

StatusFileSize
new182.67 KB

To test the scope I added also a field to a term.

tobiasb’s picture

StatusFileSize
new166.79 KB

test only patch.

tobiasb’s picture

StatusFileSize
new183.08 KB

Lets skip the test for D10.

The last submitted patch, 34: 2925609-34.test-only.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

tobiasb’s picture

StatusFileSize
new183.28 KB

Coding standards.

dasginganinja’s picture

On 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?

summit’s picture

Hi, could you give a solution for this in code please? Thanks!

seanb’s picture

Great 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.

tmanhollan’s picture

StatusFileSize
new183.28 KB
new2.09 KB

#37 worked for me. Here's an updated version that addresses #38 by changing "${field_name}_..." to "{$field_name}_...".

sleitner’s picture

+1 RTBC for patch #41

robloach’s picture

Status: Needs review » Reviewed & tested by the community

Sharing that the patch at #41 has worked here too. Thanks so much for the push!

  • tobiasb authored d444b603 on 8.x-2.x
    Issue #2925609 by tobiasb, j.cowher, seanB, tmanhollan, banoodle,...
seanb’s picture

Status: Reviewed & tested by the community » Fixed

Finally got around to commit it. Thanks everyone for your hard work! ❤️
This is a great step towards getting 2.x stable!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

grevil’s picture

We 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:

variable type is integer but applied schema class is Drupal\Core\TypedData\Plugin\DataType\StringData

Here is an exported config as an example, showing the old unchecked values still saved:

  plugin_types:
    default: default
    page: page
    block: block
    attachment: attachment
    feed: feed
    entity_browser: 0
  preselect_views:
    admin_header_slides: 0
    block_content: 0
    content: 0
    content_recent: 0
    files: 0
    frontpage: 0
    glossary: 0
    media_library: 0
    redirect: 0
    redirect_404: 0
    scheduler_scheduled_content: 0
    taxonomy_term: 0
    user_admin_people: 0
    user_profile_display: 0
    watchdog: 0
    webks_inhalt_unterseiten: 0
    who_s_new: 0
    who_s_online: 0
  enabled_settings:
    argument: argument
    offset: 0
    limit: 0
    pager: 0
    title: title

I will create a follow-up issue for this.

grevil’s picture