Page MenuHomePhabricator

API validation fails if an API param has PARAM_RANGE_ENFORCE set to false
Closed, DeclinedPublic

Description

One of my extensions has an API class where one of the parameters had "ApiBase::PARAM_RANGE_ENFORCE => false" among its values. This caused validation to fail, and I couldn't check in patches. I believe the issue is due to line 369 of tests/phpunit/structure/ApiStructureTest.php, the top line here:

				if ( isset( $config[ApiBase::PARAM_RANGE_ENFORCE] ) ) {
					$this->assertTrue(
						isset( $config[ApiBase::PARAM_MIN] ) ||
							isset( $config[ApiBase::PARAM_MAX] ),
						"$param: PARAM_RANGE_ENFORCE can only be set together with " .
							"PARAM_MIN or PARAM_MAX"
					);
				}

The code should be checking not just if the value is set, but if it's true.

By the way, I got rid of the line in my own extension, so this isn't an urgent issue for me.

Event Timeline

Which extension? Which module and parameter? Why were you setting PARAM_RANGE_ENFORCE, even to false, when you weren't setting a range to enforce?

It was the Approved Revs extension - I don't know if the module and parameter really matter. It was due to a code addition someone else made. Maybe there's no reason to set PARAM_RANGE_ENFORCE to false, but nonetheless, it's an option that I think should be handled correctly.

PARAM_RANGE_ENFORCE makes no sense, true or false, without a range. IMO it's best to keep the existing test in place.