Page MenuHomePhabricator

Community configuration defaults are not merged with partially-specified objects
Closed, ResolvedPublic5 Estimated Story Points

Description

MediaWiki-extensions-CommunityConfiguration allows extensions to specify default values within the schema. For example, this is an excerpt from SuggestedEditsSchema in GrowthExperiments:

class SuggestedEditsSchema extends JsonSchema {
	public const link_recommendation = [
		self::TYPE => self::TYPE_OBJECT,
		self::PROPERTIES => [
			'disabled' => [
				self::TYPE => self::TYPE_BOOLEAN,
				self::DEFAULT => false,
			],
			// [...]
			'underlinkedWeight' => [
				self::TYPE => self::TYPE_NUMBER,
				self::DEFAULT => LinkRecommendationTaskType::DEFAULT_SETTINGS[
					LinkRecommendationTaskType::FIELD_UNDERLINKED_WEIGHT
				],
				self::MINIMUM => 0,
				self::MAXIMUM => 1,
			],
			'minimumLinkScore' => [
				self::TYPE => self::TYPE_NUMBER,
				self::DEFAULT => LinkRecommendationTaskType::DEFAULT_SETTINGS[
					LinkRecommendationTaskType::FIELD_MIN_LINK_SCORE
				],
				self::MINIMUM => 0,
				self::MAXIMUM => 1,
			],
			// [...]
		],
	];
}

When the configuration is set to the following:

{
    "link_recommendation": {
        "disabled": true
    }
}

one would expect IConfigurationProvider::loadValidConfiguration() to return an array that would include all three properties. In this case, the call should return:

{
    "link_recommendation": {
        "disabled": true,
        "underlinkedWeight": 0.5,
        "minimumLinkScore": 0.6
    }
}

However, this is not what happens. As of now, the code that merges the actual configuration and the defaults is not recursive (see DataProvider::enhanceConfigPreValidation). For this reason, the merging recognizes link_recommendation is already defined, and there is no attempt to merge the rest.

If we were working with arrays, array_merge_recursive would do what we want, but this method does not work with objects. Not sure how to do the same with stdClass, besides re-implementing it for objects.

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

One of the ways how this shows is the defaults do not appear in Special:CommunityConfiguration for Suggested edits:

image.png (1,454×634 px, 153 KB)

FYI @KStoller-WMF @Etonkovidova.

KStoller-WMF moved this task from Inbox to Estimated tasks backlog on the Growth-Team board.
KStoller-WMF set the point value for this task to 5.Jul 9 2024, 4:19 PM

Change #1053690 had a related patch set uploaded (by Michael Große; author: Michael Große):

[mediawiki/extensions/CommunityConfiguration@master] Merge partial config with defaults

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

Change #1046970 had a related patch set uploaded (by Michael Große; author: Michael Große):

[mediawiki/extensions/GrowthExperiments@master] tests: assert tasks loaded from partial config

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

Change #1053690 merged by jenkins-bot:

[mediawiki/extensions/CommunityConfiguration@master] Merge partial config with defaults

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

Change #1054553 had a related patch set uploaded (by Michael Große; author: Michael Große):

[mediawiki/extensions/CommunityConfiguration@wmf/1.43.0-wmf.13] Merge partial config with defaults

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

Change #1054554 had a related patch set uploaded (by Michael Große; author: Michael Große):

[mediawiki/extensions/CommunityConfiguration@wmf/1.43.0-wmf.14] Merge partial config with defaults

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

Change #1054553 merged by jenkins-bot:

[mediawiki/extensions/CommunityConfiguration@wmf/1.43.0-wmf.13] Merge partial config with defaults

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

Change #1054554 merged by jenkins-bot:

[mediawiki/extensions/CommunityConfiguration@wmf/1.43.0-wmf.14] Merge partial config with defaults

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

Mentioned in SAL (#wikimedia-operations) [2024-07-16T20:29:25Z] <urbanecm@deploy1002> Started scap sync-world: Backport for [[gerrit:1054558|Ensure every test-config has valid defaults]], [[gerrit:1054553|Merge partial config with defaults (T368606)]], [[gerrit:1054554|Merge partial config with defaults (T368606)]]

Mentioned in SAL (#wikimedia-operations) [2024-07-16T20:33:13Z] <urbanecm@deploy1002> urbanecm, migr: Backport for [[gerrit:1054558|Ensure every test-config has valid defaults]], [[gerrit:1054553|Merge partial config with defaults (T368606)]], [[gerrit:1054554|Merge partial config with defaults (T368606)]] synced to the testservers (https://wikitech.wikimedia.org/wiki/Mwdebug)

Mentioned in SAL (#wikimedia-operations) [2024-07-16T20:39:20Z] <urbanecm@deploy1002> Finished scap: Backport for [[gerrit:1054558|Ensure every test-config has valid defaults]], [[gerrit:1054553|Merge partial config with defaults (T368606)]], [[gerrit:1054554|Merge partial config with defaults (T368606)]] (duration: 09m 55s)

Change #1046970 merged by jenkins-bot:

[mediawiki/extensions/GrowthExperiments@master] tests: assert tasks loaded from partial config

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

Michael moved this task from Incoming to QA on the Growth-Team (FY2024-25 Q1 Sprint 2) board.

This might be tricky to QA beyond just observing that "everything still works". This task was the proper fix for T365653, but we already had mitigations in place earlier.

The best way to see this in action might be the following:

  1. in a beta wiki, on Special:CommunityConfiguration/GrowthSuggestedEdits, in the "Add a link (Structured task)" section: add custom values to every field that takes numbers
  2. save the form
  3. observe that the custom numbers made their way to MediaWiki:GrowthExperimentsSuggestedEdits.json
  4. going back to the form, blank all the same fields in the "Add a link (Structured task)" section that take numbers
  5. save the form again
  6. observe that those fields are now gone on MediaWiki:GrowthExperimentsSuggestedEdits.json
  7. reload the form
  8. observe that the fields now show the default values.

That being said, the reason for this task is not the form, that's just an easily visible part. The reason is that the code that uses this configuration is still getting these nested default values and has still the chance to do something sensible even if parts of the config are missing.

This might be tricky to QA beyond just observing that "everything still works". This task was the proper fix for T365653, but we already had mitigations in place earlier.

The best way to see this in action might be the following:

  1. in a beta wiki, on Special:CommunityConfiguration/GrowthSuggestedEdits, in the "Add a link (Structured task)" section: add custom values to every field that takes numbers
  2. save the form
  3. observe that the custom numbers made their way to MediaWiki:GrowthExperimentsSuggestedEdits.json
  4. going back to the form, blank all the same fields in the "Add a link (Structured task)" section that take numbers
  5. save the form again
  6. observe that those fields are now gone on MediaWiki:GrowthExperimentsSuggestedEdits.json
  7. reload the form
  8. observe that the fields now show the default values.

That being said, the reason for this task is not the form, that's just an easily visible part. The reason is that the code that uses this configuration is still getting these nested default values and has still the chance to do something sensible even if parts of the config are missing.

Thank you, @Michael for the test scenarios! Very much appreciated. And although some parts of it I've done when checking individual fields, submodules - I re-checked the steps in current beta.