Problem/Motivation

We had some reports last week of a user getting 5xx errors when trying to save translations.

When looking at the logs for those days and times (Friday 26th May, Saturday 27th May), we can see some errors and warnings.

The error is due to trying to set the "translation" column to NULL, so triggers a PDO exception.
Related to the error, there is a warning for the "l10n_community_pack_string" function regarding implode.

There are two things we can improve here:
1. When adding translations, the code only checks if $tranlation === '' but that might not be enough in some cases.
2. Also, if "implode" receives a string instead of an array, it will return NULL, so it might be connected in this case.

Steps to reproduce

Proposed resolution

Change the check for a more generic PHP empty call and check the input before trying to run "implode" to make sure that it's an array.

Remaining tasks

Provide MR.

User interface changes

API changes

Data model changes

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

fjgarlin created an issue. See original summary.

fjgarlin’s picture

Issue summary: View changes
fjgarlin’s picture

Issue summary: View changes

fjgarlin’s picture

Issue summary: View changes
fjgarlin’s picture

Title: Edge case: trying to store NULL translations prokes 5XX error » Edge case: trying to store NULL translations provokes 5XX error
fjgarlin’s picture

Status: Active » Needs review
bramdriesen’s picture

Status: Needs review » Reviewed & tested by the community

Followed this thread in Slack. Code changes look straight forward to me so RTBC.

bramdriesen’s picture

Probably worth double checking if the same issue is present in the ported code for the D9/10 release.

fjgarlin’s picture

Good point. It seems like it could also happen there based on this: https://git.drupalcode.org/issue/l10n_server-3363293/-/blob/3.0.x/l10n_s...

If the current 7.x fix gets merged then we can follow up with a similar one for 3.0.x? 2.0.x? or we can chat about it on the #localize channel.

fmb’s picture

The 2.0.x branch is abandoned. A fix is welcome on the 3.0.x branch. If you need to run a local instance, the code of the platfom is on GitLab.

fjgarlin’s picture

After reviewing the code in more depth, I don't think this will happen in the 3.0.x branch.

The parameters of the affected functions are typed. See:
* public static function addSuggestion(int $sid, string $translation, string $langcode, ...
* protected function packString(array $strings)...

Also, the code is doing some additional checks, before calling them, which will force them to be the right type.

ie:

if ($tid === 'new' && $all_values > $empty_values) {
            $tid = $this->l10nPo->addSuggestion($sid, $this->packString($options['value']...

where $all_values will only be greater than $empty_values if $options['value'] is an array and is not empty.

So it seems like the fix is only needed on the 7.x version.

bramdriesen’s picture

Great, thanks for checking @fjgarlin. Still RTBC in that case

drumm made their first commit to this issue’s fork.

  • drumm committed c5e94020 on 7.x-1.x authored by fjgarlin
    Issue #3363293 by fjgarlin: Edge case: trying to store NULL translations...
drumm’s picture

Status: Reviewed & tested by the community » Fixed

Merged & deployed, thanks!

Status: Fixed » Closed (fixed)

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