Installed the latest dev build. Upon updating the database I get the following error:

dynamic_entity_reference module

Update #8001

Failed: Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes: ALTER TABLE {courier_template_collection} CHANGE `owner__target_id` `owner__target_id` VARCHAR(255) NOT NULL COMMENT 'The ID of the target entity.'; Array ( ) in dynamic_entity_reference_update_8001() (line 44 of /home/solution/public_html/surf-dates.com/modules/contrib/dynamic_entity_reference/dynamic_entity_reference.install).

CommentFileSizeAuthor
#13 2769603_13.patch3.36 KBchx
#13 2769603_13_fail.patch682 byteschx
#11 2769603_11.patch2.69 KBchx
#9 2769603_9.patch2.25 KBchx

Comments

platinum1 created an issue. See original summary.

chx’s picture

Care to share a structure dump of the table in question?

chx’s picture

Also, what's your core version.

platinum1’s picture

The version is 8.2.x-dev

jibran’s picture

Status: Active » Postponed (maintainer needs more info)

As mentioned in #2. Please share the output of drush sqlq "SHOW CREATE TABLE courier_template_collection;". It seems like you are using http://drupal.org/project/courier and the entity in question is http://cgit.drupalcode.org/courier/tree/src/Entity/TemplateCollection.php. I'll ping @dpi about it.

jibran’s picture

Priority: Normal » Major

@chx: I'm looking at TemplateCollection::baseFieldDefinitions() and this entity has two DER basefields. One field(owner) with cardinality 1 and other(templates) with unlimited. I don't think it is related to #2766193: Add tests for multiple base fields because field with an unlimited cardinality will have a separate table and basefield in question here is owner not templates.

platinum1’s picture

courier_template_collection CREATE TABLE `courier_template_collection` (\n `id` int(10) unsigned NOT NULL AUTO_INCREMENT,\n `context` varchar(255) CHARACTER SET ascii DEFAULT NULL COMMENT 'The ID of the target entity.',\n `owner__target_id` int(10) unsigned DEFAULT NULL COMMENT 'The ID of the target entity.',\n `owner__target_type` varchar(32) DEFAULT NULL COMMENT 'The Entity Type ID of the target entity.',\n PRIMARY KEY (`id`),\n KEY `courier_template_collection__b3acb6e86e` (`context`),\n KEY `courier_template_collection__2d7659b160` (`owner__target_id`,`owner__target_type`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='The base table for courier_template_collection entities.'

jibran’s picture

Status: Postponed (maintainer needs more info) » Active
courier_template_collection	CREATE TABLE `courier_template_collection` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `context` varchar(255) CHARACTER SET ascii DEFAULT NULL COMMENT 'The ID of the target entity.',
 `owner__target_id` int(10) unsigned DEFAULT NULL COMMENT 'The ID of the target entity.',
 `owner__target_type` varchar(32) DEFAULT NULL COMMENT 'The Entity Type ID of the target entity.',
 PRIMARY KEY (`id`),
 KEY `courier_template_collection__b3acb6e86e` (`context`),
 KEY `courier_template_collection__2d7659b160` (`owner__target_id`,`owner__target_type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='The base table for courier_template_collection entities.'

Thank you!

chx’s picture

Status: Active » Needs review
StatusFileSize
new2.25 KB

This looks like a core bug (when the new spec of an alter is a varchar and has an index defined on it then the indexing shortening mechanism should fire) but fixing it there is a bother so let's just play dumb contrib author and code around it. Semantically this is more correct anyways.

Status: Needs review » Needs work

The last submitted patch, 9: 2769603_9.patch, failed testing.

chx’s picture

Status: Needs work » Needs review
StatusFileSize
new2.69 KB
jibran’s picture

Nice fix! Let's file a core bug as well. Can we somehow test this fix?

chx’s picture

StatusFileSize
new682 bytes
new3.36 KB

Yes, yes, we can. It's untrivial to test, it's ugly to test but it's doable.

jibran’s picture

Status: Needs review » Reviewed & tested by the community

Created #2770321: MySQL Schema class needs to check for existing indexes for alter queries for #9 and created #2770319: Testbot MySQL config doesn't use large prefix hiding potential errors for not failing patch in #13.
This is ready imo let's wait for @platinum1 to test it.

jibran’s picture

Status: Reviewed & tested by the community » Needs review
  1. +++ b/dynamic_entity_reference.install
    @@ -5,6 +5,7 @@
     /**
    
    +++ b/src/Tests/Update/DerUpdateTest.php
    @@ -35,6 +35,8 @@ class DerUpdateTest extends UpdatePathTestBase {
    +    // Cause 1071 Specified key was too long; max key length is 767 bytes.
    +    \Drupal::database()->query('ALTER TABLE {entity_test__field_test} ROW_FORMAT=compact');
    

    This is a mysql bug https://bugs.mysql.com/bug.php?id=68453 and as it turns out if you set innodb_large_prefix OFF the error will go away.

  2. +++ b/src/Plugin/Field/FieldType/DynamicEntityReferenceItem.php
    @@ -99,12 +99,12 @@ class DynamicEntityReferenceItem extends EntityReferenceItem {
    -        'type' => 'varchar',
    +        'type' => 'varchar_ascii',
    ...
    -        'type' => 'varchar',
    +        'type' => 'varchar_ascii',
    

    I don't think we should change this at all to fix a core bug #2770321: MySQL Schema class needs to check for existing indexes for alter queries. As far as this issue is concerned I think it is a won't fix and we should fix it in core.

chx’s picture

Status: Needs review » Reviewed & tested by the community

Core doesn't support forcing large indexes (there's no ROW_FORMAT support as far as I can see) which a 255 + 32 utf8mb4 would create but semantically this is correct because machine names are ASCII and not higher Unicode characters.

jibran’s picture

Ok, let's commit #11 instead of #13. We don't need to test mysql bug in DER.

chx’s picture

Status: Reviewed & tested by the community » Needs work

We need to, we actually need to because people will have COMPACT tables and we need to make sure we are doing the right update even for them. Yes, if the alterTable method would truncate the index itself as the core issue says it should then there would be no problem but it's core and I expect it to be not fixed any time soon since I won't. The only change we need to do there is to wrap it in if (Database::getConnection()->driver() == 'mysql').

chx’s picture

Status: Needs work » Needs review
StatusFileSize
new2.51 KB

Like this.

chx’s picture

StatusFileSize
new5.2 KB

Opsie, that was just the fail patch, this is the complete one.

jibran’s picture

Status: Needs review » Reviewed & tested by the community

Seems like all the DB drivers are happy.

platinum1’s picture

Thank you for the patch. Error is gone.

  • chx committed f95f4cb on 8.x-2.x
    Issue #2769603 by chx: Syntax error or access violation: 1071 Specified...
chx’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for the valuable report and the quick feedback! Committed.

Status: Fixed » Closed (fixed)

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