Page MenuHomePhabricator

ZObjectFactory::create() fails when object keys are local not global
Closed, ResolvedPublicBUG REPORT

Description

The observed failure involves Z22s containing a ZMap for the value of Z22K2; that is, the new response envelope format with metadata map.

Steps to replicate the issue (include links if applicable):

  • In ZResponseEnvelopeTest.php::testCreation_factory_mapped_errors, in the JSON input string: for each Z882 / ZPair, change the first element key from Z882K1 to K1 and the 2nd element key from Z882K2 to K2. For example, change this ZPair
                        {
				"Z882K1": "errors",
				"Z882K2": {
					"Z1K1": "Z5",
					"Z5K1": "Z507",
					"Z5K2": "Executor returned an empty response."
				},
				"Z1K1": {
					"Z1K1": "Z7",
					"Z7K1": "Z882",
					"Z882K1": "Z6",
					"Z882K2": "Z1"
				}
			}

to this:

                     {
				"K1": "errors",
				"K2": {
					"Z1K1": "Z5",
					"Z5K1": "Z507",
					"Z5K2": "Executor returned an empty response."
				},
				"Z1K1": {
					"Z1K1": "Z7",
					"Z7K1": "Z882",
					"Z882K1": "Z6",
					"Z882K2": "Z1"
				}
			}

Note: the Z1K1 value remains unchanged. You can change just the pair shown above (with key "errors"), or you can change all of the pairs; the failure will arise either way.

  • Run the PHP unit tests:

docker-compose exec mediawiki php tests/phpunit/phpunit.php extensions/WikiLambda/tests/phpunit/

What happens?:
Even though the modified test input is a valid Z22, the test now fails. It appears that the ZPairs in the object returned from ZObjectFactory::create() are missing both first and 2nd elements; that is, they each contain only the Z1K1. This, in turn, causes the subsequent call to
$testObject->hasErrors()
to throw an exception (Error: Call to a member function getZValue() on null)

What should have happened instead?:
The call to ZObjectFactory::create should have created a valid ZObject, without any missing elements.

Software version (skip for WMF-hosted wikis like Wikipedia):

Other information (browser name/version, screenshots, etc.):
The Z22s returned by the orchestrator use "K1" and "K2" for the first and 2nd element keys in a ZPair, not "Z882K1" and "Z882K2". Therefore, the bug described here prevents us from using the new response envelope format. In particular, this problem arises in APIPerformTest.php::executeFunctionCall(), each time it calls ZObjectFactory::create.

Event Timeline

Jdforrester-WMF renamed this task from ZObjectFactory::create() fails on certain valid JSON inputs to ZObjectFactory::create() fails when object keys are local not global.Jul 27 2022, 5:03 PM

Change 817833 had a related patch set uploaded (by Jforrester; author: Jforrester):

[mediawiki/extensions/WikiLambda@master] ZObjectFactory: Support local keys when provided

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

Change 817833 merged by jenkins-bot:

[mediawiki/extensions/WikiLambda@master] ZObjectFactory: Support local keys when provided

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