We have a feed import that fails (we have no clue why).
Looking at the "Log" tab did not help much as it crashed. It uses the locale() function to display the (translated) error text which in this case throws an PDOException:

PDOException: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'source' at row 1: INSERT INTO {locales_source} (location, version, source, context, textgroup) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4); Array ( ..[very long].. ) ) in locale() (Zeile 714 von /html/drupal/modules/locale/locale.module).

(That is line 714 in /html/drupal/modules/locale/locale.module)

It is the "else" code block "We don't have the source string, cache this as untranslated...." with a call to "db_merge()->execute" which fails.

My dirty patch is to call this "else"-block only for texts with less than 128 Bytes (mb_strlen) and calling $locale_t[$langcode][$context][$string] = TRUE; only otherwise.

It would be better to catch this kind of PDOException with SQLSTATE[22001] and probably just forget it.
The "$locale_t... = TRUE;" is needed here, too, because drupal make calls to locale() over and over otherwise.

Another question is why to try to translate an exception's message as it might hide important details. Nevertheless there'a a bug in the locale() function or the database code used by it.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tylernichols’s picture

I have the same issue.

RobLoach’s picture

Version: 7.18 » 8.x-dev
Component: language system » locale.module

The size of locale_sources' source field is too small to hold the data you're inserting. Either don't insert so much data, or make the source field take more data:

       'source' => array(
         'type' => 'text',
         'mysql_type' => 'blob',
         'size' => 'big',
         'not null' => TRUE,
         'description' => 'The original string in English.',
       ),
function locale_update_7006() {
  db_change_field('locales_source', 'source', 'source', array(
    'type' => 'text',
    'mysql_type' => 'blob',
    'size' => 'big',
    'not null' => TRUE,
    'description' => 'The original string in English.',
  ));
}

The lack of patch is because it's more seeing if this helps the Drupal 7 folk first. The fix would need to get into Drupal 8 before backporting to 7.

worldlinemine’s picture

This is in response to comment #2 only:

I believe that the potential negative performance impact of increasing the size of the blob outweighs the benefit. The purpose of the Locale module is to support translations in the interface in which case 16kb would appear to be more then sufficient. I would not recommend making the change suggested in comment #2.

kardave’s picture

Hi all,

I had this issue, and not even #2 could help me.
I had a very large string in watchdog, and dblog page failed to load because the string was forced to be saved into locales_source.source.

Not having enough time for debugging how to eliminate the large string (deleting from watchdog did not do it) I had no choice.
My only remained solution was to patch the core (I know, never ever even think of it) temporary:

if(strlen($string) > 50000) {
    return $string;
}

/modules/locale/locale.module line 671

After some time I will remove this and see if survived the large string, but now it saved me a lot of debugging time.
I Hope this helps someone someday.

broon’s picture

This still happens (of course. since it hasn't been fixed/backported yet).
During development of a module, which logs some events to watchdog I made a mistake and a complete view including 25 full nodes was var_dumped into the watchdog message. Since I was on a multilingual site and currently in another language interface than English, the "Show Recent Log Posts" page fails with the above error. It works fine when switching to English.

ressa’s picture

I am experiencing this issue now, but @kardave's temporary fix doesn't seem to work any more... Does anyone know how to fix it, also even if only temporary?

mecano’s picture

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

andypost’s picture

Title: Function locale() throws PDOException for long texts not already translated » Field locales_source.source is not suitable for long texts and huge config objects
Version: 8.2.x-dev » 8.3.x-dev
Issue tags: +D8MI, +language-base, +language-config
Related issues: +#2836206: [Translations] Translation of big webforms broken

This is because mysql limit for blob field is 64k
Faced with that in d8 where config object is bigger than that

BTW looks the same limit we have for translation

jrockowitz’s picture

The attached patch is port of #4 to Drupal 8. All it does is store an empty string in the 'locales_source' and 'locales_target' table if the source string is greater than 64KB.

This is only a temporary solution. The most immediate side-effect I am seeing is when translating config the source string no longer appears because it is empty.

jrockowitz’s picture

Status: Active » Needs review
FileSize
1007 bytes

Here is the patch and I am setting it to needs review just get the testbot to review it.

Status: Needs review » Needs work

The last submitted patch, 12: field-1885192-12.patch, failed testing.

jrockowitz’s picture

Status: Needs review » Needs work

The last submitted patch, 14: field-1885192-14.patch, failed testing.

andypost’s picture

Issue tags: +sprint

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Sutharsan’s picture

The watchdog is the most likely place where too long strings get passed to t(), but it any code may make this “mistake”. The translation system should guard itself for this types of errors.

I see two options: 1. Truncate the string; 2. Throw an exception.

I agree that increasing the table size is not the solution. Exceptional cases like these cannot justify any performance this change may have.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

markdc’s picture

I just ran into this issue on 8.9.13.

#14 applied and works.

ankithashetty’s picture

Status: Needs work » Needs review
FileSize
1.11 KB
1.28 KB

Rerolled the patch in #14, thanks!

andypost’s picture

  1. +++ b/core/modules/locale/src/StringDatabaseStorage.php
    @@ -463,6 +464,14 @@ protected function dbStringSelect(array $conditions, array $options = []) {
    +    if (Unicode::strlen($string->getString()) > 64000) {
    

    There's no such function in D9, see https://www.drupal.org/node/2850048

  2. +++ b/core/modules/locale/src/StringDatabaseStorage.php
    @@ -463,6 +464,14 @@ protected function dbStringSelect(array $conditions, array $options = []) {
    +      $string->setString('');
    

    This event needs to be logged in watchdog (warning at least) so users can catch this bugs

ankithashetty’s picture

Addressed #28.1, thanks.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

joseph.olstad’s picture

Note: in my tests I did not have this issue with PostgreSQL, however I came across it with MySQL v8.0.28

so far I was able to mitigate my use case by:
#2844452: Export configuration YAML strings as multiline
#3271926: mysql 1406 Data too long for column 'source' at row 1 insert into locales_source

larowlan’s picture

Status: Needs work » Postponed (maintainer needs more info)
Issue tags: +Bug Smash Initiative

With those two related items that @joseph.olstad referenced now fixed, is this still an issue

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

joseph.olstad’s picture

Curiously enough, for some reason I noticed that webforms configuration that is edited by ckeditor generates \r\n even on the recent core release 9.3.16.

Postgresql has a larger blob, doesn't have this issue but with MySQL variants I had issues importing large webform config yml , not sure why ckeditor would be outputing \r\n or where to turn this bad ckeditor behavior off as it affects the processing of translations that eventually go into the locales table.

Sorry not much in dept here but I did check out the blob sizes for MySQL:

TINYBLOB   : L < 2^8  =           256 Bytes
BLOB       : L < 2^16 =        65,536 Bytes
MEDIUMBLOB : L < 2^24 =    16,777,216 Bytes
LONGBLOB   : L < 2^32 = 4,294,967,296 Bytes

MySQL seems to blow up on 64K limits , the blob type is used in a few places.

Drupal running PostgreSQL 12 that I also use doesn't have this issue because it's blob field has different /higher limits.

As a workaround I manually edited my exported YML, replaced \r\n with \n and everything imported correctly with MySQL, however today someone brought up to me a large webform that is unable to save a webform translation in the ui after a certain limit. Seems like two different but similar issues going on, haven't done a deep dive on this yet.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Wonder if this should be reopened?

emptyvoid’s picture

I've got this issue in Drupal 9 and Drupal 10.
Having the body field or content fields with both editorial content as well as full HTML on larger pages causes this local field validation to fail every single time.

I have to patch each release so that the 10,000+ records and updates will actually complete in my builds.

Most recent Patch attached.
This commits to both Drupal 9.5.10 and Drupal 10.1.2