Page MenuHomePhabricator

TypeError: Argument 2 passed to ContentModelChange::doContentModelChange() must be of the type string, null given, called in /srv/mediawiki/php-1.41.0-wmf.16/includes/api/ApiChangeContentModel.php on line 82
Closed, ResolvedPublicPRODUCTION ERROR

Description

Steps to reproduce:

  • use the API sandbox (easiest this way), e.g. on testwiki
  • select action=changecontentmodel
  • fill in a title, e.g. User:Lucas Werkmeister (WMDE)/sandbox
  • select a different model, e.g. text
  • let the API sandbox auto-fill the token
  • do not fill in a summary
  • make request
Error
normalized_message
[{reqId}] {exception_url}   TypeError: Argument 2 passed to ContentModelChange::doContentModelChange() must be of the type string, null given, called in /srv/mediawiki/php-1.41.0-wmf.16/includes/api/ApiChangeContentModel.php on line 82
exception.trace
from /srv/mediawiki/php-1.41.0-wmf.16/includes/content/ContentModelChange.php(251)
#0 /srv/mediawiki/php-1.41.0-wmf.16/includes/api/ApiChangeContentModel.php(82): ContentModelChange->doContentModelChange(DerivativeContext, NULL, boolean)
#1 /srv/mediawiki/php-1.41.0-wmf.16/includes/api/ApiMain.php(1915): ApiChangeContentModel->execute()
#2 /srv/mediawiki/php-1.41.0-wmf.16/includes/api/ApiMain.php(892): ApiMain->executeAction()
#3 /srv/mediawiki/php-1.41.0-wmf.16/includes/api/ApiMain.php(863): ApiMain->executeActionWithErrorHandling()
#4 /srv/mediawiki/php-1.41.0-wmf.16/api.php(95): ApiMain->execute()
#5 /srv/mediawiki/php-1.41.0-wmf.16/api.php(48): wfApiMain()
#6 /srv/mediawiki/w/api.php(3): require(string)
#7 {main}
Impact

Minor logspam; users can’t change content model without specifying a summary (which is probably discouraged anyways)

Notes

Details

Request URL
https://test.wikipedia.org/w/api.php

Event Timeline

I suppose there’s two possible solutions:

default the summary to the empty string
diff --git a/includes/api/ApiChangeContentModel.php b/includes/api/ApiChangeContentModel.php
index 870355c12e..895e61af89 100644
--- a/includes/api/ApiChangeContentModel.php
+++ b/includes/api/ApiChangeContentModel.php
@@ -78,7 +78,7 @@ public function execute() {
 		try {
 			$status = $changer->doContentModelChange(
 				$this->getContext(),
-				$params['summary'],
+				$params['summary'] ?? '',
 				$params['bot']
 			);
 		} catch ( ThrottledError $te ) {
make the summary required
diff --git a/includes/api/ApiChangeContentModel.php b/includes/api/ApiChangeContentModel.php
index 870355c12e..2eacd53b3b 100644
--- a/includes/api/ApiChangeContentModel.php
+++ b/includes/api/ApiChangeContentModel.php
@@ -123,6 +123,7 @@ public function getAllowedParams() {
 			],
 			'summary' => [
 				ParamValidator::PARAM_TYPE => 'string',
+				ParamValidator::PARAM_REQUIRED => true,
 			],
 			'tags' => [
 				ParamValidator::PARAM_TYPE => 'tags',

The former is probably closer to what used to happen before the string parameter type was added to doContentModelChange(); the latter might be considered a breaking change to the API?

Krinkle moved this task from Untriaged to Jul 2023 on the Wikimedia-production-error board.

Looks like the special page doesn’t require a summary either, so let’s just default it to the empty string.

Change 938209 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/core@master] api: Default wbchangecontentmodel summary to empty

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

Change 938209 merged by jenkins-bot:

[mediawiki/core@master] api: Default changecontentmodel summary to empty

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