Page MenuHomePhabricator

TypeError: Argument 9 passed to ContentTranslation\DTO\PublishedTranslationDTO::__construct() must be of the type string, null given
Closed, ResolvedPublicPRODUCTION ERROR

Description

Recently, we added the "targetUrl" variable to the "PublishedTranslationDTO" class, which corresponds to the "translation_target_url" field inside "cx_translations" table. The "targetUrl" argument in the PublishedTranslationDTO constructor is required to be a (non-nullable) string.

Regarding this decision, we always set the "translation_target_url" field inside the corresponding row of the "cx_translations" table, when publishing an article (ApiContentTranslationPublish class) or a section (ApiSectionTranslationPublish class). Thus, the argument passed to the "PublishedTranslationDTO" constructor is indeed expected to be a string (since "translation_target_url" is always non-null for translations that have been published).

However, there are some, yet unidentified, cases where the "targetUrl" parameter is null, leading to PHP error and broken published translation fetching requests. Such an error, as it appears in Logstash, is provided below:

{
  "_index": "logstash-deploy-1-7.0.0-1-2023.09.29",
  "_id": "5eJx4IoBi6TOjMqmMmxG",
  "_score": 1,
  "_source": {
    "tags": [
      "input-kafka-rsyslog-udp-localhost",
      "rsyslog-udp-localhost",
      "kafka",
      "es",
      "es"
    ],
    "message_checksum": "3d163c71236ee64c61cf1558e7b1191a",
    "http_method": "GET",
    "severity": "err",
    "server": "el.wikipedia.org",
    "host": "mw1359",
    "wiki": "elwiki",
    "caught_by": "entrypoint",
    "channel": "exception",
    "url": "/w/api.php?action=query&assert=user&format=json&formatversion=2&list=contenttranslation&sectiontranslationsonly=true&type=published",
    "timestamp": "2023-09-29T10:17:08+00:00",
    "logsource": "mw1359",
    "message": "[8cb75f1d-8c37-44c2-a814-a0438059d47b] /w/api.php?action=query&assert=user&format=json&formatversion=2&list=contenttranslation&sectiontranslationsonly=true&type=published   TypeError: Argument 9 passed to ContentTranslation\\DTO\\PublishedTranslationDTO::__construct() must be of the type string, null given, called in /srv/mediawiki/php-1.41.0-wmf.28/extensions/ContentTranslation/includes/Store/SectionTranslationStore.php on line 299",
    "exception_url": "/w/api.php?action=query&assert=user&format=json&formatversion=2&list=contenttranslation&sectiontranslationsonly=true&type=published",
    "monolog_level": 400,
    "facility": "user",
    "referrer": null,
    "normalized_message": "[{reqId}] {exception_url}   TypeError: Argument 9 passed to ContentTranslation\\DTO\\PublishedTranslationDTO::__construct() must be of the type string, null given, called in /srv/mediawiki/php-1.41.0-wmf.28/extensions/ContentTranslation/includes/Store/Secti",
    "@version": 1,
    "type": "mediawiki",
    "mwversion": "1.41.0-wmf.28",
    "phpversion": "7.4.33",
    "level": "ERROR",
    "exception": {
      "trace": "from /srv/mediawiki/php-1.41.0-wmf.28/extensions/ContentTranslation/includes/DTO/PublishedTranslationDTO.php(19)\n#0 /srv/mediawiki/php-1.41.0-wmf.28/extensions/ContentTranslation/includes/Store/SectionTranslationStore.php(299): ContentTranslation\\DTO\\PublishedTranslationDTO->__construct(integer, string, string, string, string, string, string, string, NULL, array)\n#1 /srv/mediawiki/php-1.41.0-wmf.28/extensions/ContentTranslation/includes/ActionApi/ApiQueryContentTranslation.php(156): ContentTranslation\\Store\\SectionTranslationStore->findPublishedSectionTranslationsByUser(integer, NULL, NULL, integer, NULL)\n#2 /srv/mediawiki/php-1.41.0-wmf.28/extensions/ContentTranslation/includes/ActionApi/ApiQueryContentTranslation.php(62): ContentTranslation\\ActionApi\\ApiQueryContentTranslation->run()\n#3 /srv/mediawiki/php-1.41.0-wmf.28/includes/api/ApiQuery.php(695): ContentTranslation\\ActionApi\\ApiQueryContentTranslation->execute()\n#4 /srv/mediawiki/php-1.41.0-wmf.28/includes/api/ApiMain.php(1931): ApiQuery->execute()\n#5 /srv/mediawiki/php-1.41.0-wmf.28/includes/api/ApiMain.php(908): ApiMain->executeAction()\n#6 /srv/mediawiki/php-1.41.0-wmf.28/includes/api/ApiMain.php(879): ApiMain->executeActionWithErrorHandling()\n#7 /srv/mediawiki/php-1.41.0-wmf.28/api.php(95): ApiMain->execute()\n#8 /srv/mediawiki/php-1.41.0-wmf.28/api.php(48): wfApiMain()\n#9 /srv/mediawiki/w/api.php(3): require(string)\n#10 {main}",
      "message": "Argument 9 passed to ContentTranslation\\DTO\\PublishedTranslationDTO::__construct() must be of the type string, null given, called in /srv/mediawiki/php-1.41.0-wmf.28/extensions/ContentTranslation/includes/Store/SectionTranslationStore.php on line 299",
      "code": 0,
      "class": "TypeError",
      "file": "/srv/mediawiki/php-1.41.0-wmf.28/extensions/ContentTranslation/includes/DTO/PublishedTranslationDTO.php:19"
    },
    "program": "mediawiki",
    "@timestamp": "2023-09-29T10:17:08.641Z",
    "servergroup": "api_appserver",
    "shard": "s3",
    "reqId": "8cb75f1d-8c37-44c2-a814-a0438059d47b"
  },
  "fields": {
    "@timestamp": [
      "2023-09-29T10:17:08.641Z"
    ]
  }
}

For now, the proposed approach is to let the "targetUrl" parameter be nullable, to avoid blocking the fetching requests, until the root cause is found.

Details

Request URL
https://el.wikipedia.org/w/api.php?action=query&assert=*&format=*&formatversion=*&list=contenttranslation&sectiontranslationsonly=true&type=published

Event Timeline

ngkountas triaged this task as Unbreak Now! priority.Sep 29 2023, 12:34 PM
ngkountas created this task.

Change 962000 had a related patch set uploaded (by Nik Gkountas; author: Nik Gkountas):

[mediawiki/extensions/ContentTranslation@master] CX PublishedTranslationDTO: Let target url to be nullable

https://gerrit.wikimedia.org/r/962000

Possible hint for the investigation:
Initially, I created a draft translation for the Agnosia article, from en to el, on desktop (by translating sentences in the lead section and one more section). Then, I continued the draft translation on mobile, publishing the lead section with target title "Αγνωσία", which is a valid translation of the source title. However, "Αγνωσία" page already existed (which I couldn't know during the translation), as a redirection to a totally different article. Publishing was completed though, as the added lead section was added as new section inside the redirection page.

After this incident, the fetching requests for the published translations started failing, which indicates that somehow the above translation that I created, somehow ended up having null "translation_target_url".

It would be useful to validate it by checking the actual database records.

Change 962000 merged by jenkins-bot:

[mediawiki/extensions/ContentTranslation@master] CX PublishedTranslationDTO: Let target url to be nullable

https://gerrit.wikimedia.org/r/962000

This will be difficult to QA. Hence we would continue to monitor this for a bit to ensure it does not resurface

Based on the logstash link that Niklas provided above, the issue doesn't occur anymore. @Pginer-WMF I believe that we can close this task as done.