Problem/Motivation

#1167144: Make cache backends responsible for their own storage created a regression in Drupal\Core\Database\Driver\mysql\Schema->prepareComment() that truncates schema comments improperly. Currently, substr() is being used to truncate the comments. This is a problem when quotation marks are used in the comment.

Proposed resolution

Use Unicode::truncate.

Remaining tasks

  • Review and RTBC.

User interface changes

None

API changes

Original report by @ivanjaros

The watchdog table, which is defined by a dblog module in dblog_schema() function, will break the installation process due to a bug where the column definition is appended to the column's name which results in a column with type` varchar(64) NOT NULL DEFAULT '' COMMENT 'Type of log message, for example "user name.

The description of the type column is 'Type of log message, for example "user" or "page not found."'.
Exchanging the double quotes with the single quotes, "Type of log message, for example 'user' or 'page not found.'", seems to fix the problem.

PHP Version 5.4.17
DB: 5.5.34-MariaDB-log

Drupal 8 Alpha 12 installs just fine. But Alpha 13 and HEAD(4.7.2014 17:00) have this issue. I cannot confirm or deny this issue when using drush for installation ony with UI.

@pwolanin noted that it can be related to \Drupal\Core\Database\Driver\mysql\Schema::prepareComment().

Comments

catch’s picture

Version: 8.0-alpha13 » 8.x-dev
Issue tags: +beta target, +D8 upgrade path
junedkazi’s picture

Status: Active » Needs review
cilefen’s picture

StatusFileSize
new714 bytes

I just tested against HEAD with MariaDB 5.5.35 and PHP 5.4.24 but the problem does not occur. D8 is the same as D7 in the schema definition for this column but yes, prepareComment() is different in D8. The D8 version uses substr to trim the comment to a maximum length but D7 uses truncate_utf8.

I performed an informal search of core for double-quotes used inside MySQL comments and found this:

core/modules/comment/comment.install:    'description' => 'Maintains statistics of entity and comments posts to show "new" and "updated" flags.',
core/modules/dblog/dblog.install:        'description' => 'Type of log message, for example "user" or "page not found."',

The definition in comment.install is the same as D7 but it is truncated wrongly for me in D8. So, I think we are looking at a regression in prepareComment().

Please test with this patch and see if it fixes this column in dblog and the table comment for comment_entity_statistics. If it does, we'll retitle this issue.

catch’s picture

Component: dblog.module » database system
alexpott’s picture

Status: Needs review » Needs work

#1167144: Make cache backends responsible for their own storage changed from truncate_utf8() to substr - we probably should change to use Unicode::truncate()

alexpott’s picture

Issue tags: +TCDrupal 2014
cilefen’s picture

Status: Needs work » Needs review
StatusFileSize
new917 bytes
new993 bytes
cilefen’s picture

Title: watchdog table breaks installation on MariaDB 5.5.34 » MySQL column and table comments are not truncated properly

Title change.

andyceo’s picture

Do we need tests here?

catch’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Yes let's add tests.

cilefen’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new1.93 KB
new3.02 KB

Tests.

cilefen’s picture

StatusFileSize
new579 bytes
new2.97 KB

Removed a debugging line.

cilefen’s picture

Issue summary: View changes
cilefen’s picture

Issue summary: View changes
cilefen’s picture

dawehner’s picture

Can you please upload a -FAIL test to proove that the patch solves the problem?

+++ b/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php
@@ -492,7 +493,7 @@ public function prepareComment($comment, $length = NULL) {
-      $comment = substr($this->connection->prefixTables($comment), 0, $length);
+      $comment = Unicode::truncate($this->connection->prefixTables($comment), $length, TRUE, TRUE);

Do we really want to support unicodes here? Well, it is just on schema time, so it seems okay.

cilefen’s picture

The last submitted patch, 17: mysql_column_and_table-2297993-17-TEST-ONLY.patch, failed testing.

cilefen’s picture

Status: Needs review » Needs work
Issue tags: -TCDrupal 2014 +Needs reroll
marthinal’s picture

Status: Needs work » Needs review
Issue tags: +Amsterdam2014
StatusFileSize
new2 KB
new2.99 KB

Rerolled

The last submitted patch, 21: 2297993-21-only-test.patch, failed testing.

star-szr’s picture

Status: Needs review » Needs work
Issue tags: -Needs reroll

Just context changes in the patch, reroll looks good. And we can see the fail from the test-only patch in #17, fine that the new one doesn't apply. Thanks @marthinal!

+++ b/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php
@@ -492,7 +493,7 @@ public function prepareComment($comment, $length = NULL) {
-      $comment = substr($this->connection->prefixTables($comment), 0, $length);
+      $comment = Unicode::truncate($this->connection->prefixTables($comment), $length, TRUE, TRUE);;

Let's remove the double semi-colon.

Other than that looks good to me.

marthinal’s picture

Status: Needs work » Needs review
StatusFileSize
new2.03 KB
new2.99 KB

Thanks for reviewing @Cotsser :)

Done.

star-szr’s picture

Status: Needs review » Reviewed & tested by the community

Thanks @marthinal.

Interdiff next time, please :)

Looks good and has test coverage, RTBC!

The last submitted patch, 24: 2297993-23-only-test.patch, failed testing.

catch’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php
@@ -13,6 +13,7 @@
 use Drupal\Core\Database\SchemaObjectExistsException;

+++ b/core/modules/system/src/Tests/Database/SchemaTest.php
@@ -212,6 +213,12 @@ function tryInsert($table = 'test_table') {
+      $db_type = Database::getConnection()->databaseType();

Minor, but no need to assign this to a variable - can just use the method in the if statement directly.

marthinal’s picture

Status: Needs work » Needs review
StatusFileSize
new929 bytes
new2.96 KB

Ok let's do it :)

star-szr’s picture

Status: Needs review » Reviewed & tested by the community

Looks good, thanks @marthinal.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 62b9d58 and pushed to 8.0.x. Thanks!

  • alexpott committed 62b9d58 on
    Issue #2297993 by cilefen, marthinal, ivanjaros: Fixed MySQL column and...

Status: Fixed » Closed (fixed)

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