Page MenuHomePhabricator

ImportConstraintEntities causes RateLimitingIdGenerator rate limit error
Open, Needs TriagePublicBUG REPORT

Description

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

  • Add Wikibase Quality Constraints to your MediaWiki
  • Run php maintenance/run.php WikibaseQualityConstraints:ImportConstraintEntities.php to import data entities

What happens?:

Wikibase\Lib\Store\StorageException from line 34 of /var/www/html/w/extensions/Wikibase/repo/includes/Store/RateLimitingIdGenerator.php: As an anti-abuse measure, you are limited from performing this action too many times in a short space of time, and you have exceeded this limit.
Please try again in a few minutes.
#0 /var/www/html/w/extensions/Wikibase/repo/includes/Store/Sql/WikiPageEntityStore.php(179): Wikibase\Repo\Store\RateLimitingIdGenerator->getNewId()
#1 /var/www/html/w/extensions/Wikibase/repo/includes/Store/Sql/WikiPageEntityStore.php(266): Wikibase\Repo\Store\Sql\WikiPageEntityStore->assignFreshId()
#2 /var/www/html/w/extensions/Wikibase/lib/includes/Store/TypeDispatchingEntityStore.php(85): Wikibase\Repo\Store\Sql\WikiPageEntityStore->saveEntity()
#3 /var/www/html/w/extensions/WikibaseQualityConstraints/maintenance/ImportConstraintEntities.php(180): Wikibase\Lib\Store\TypeDispatchingEntityStore->saveEntity()
#4 /var/www/html/w/extensions/WikibaseQualityConstraints/maintenance/ImportConstraintEntities.php(146): WikibaseQuality\ConstraintReport\Maintenance\ImportConstraintEntities->importEntityFromJson()
#5 /var/www/html/w/extensions/WikibaseQualityConstraints/maintenance/ImportConstraintEntities.php(105): WikibaseQuality\ConstraintReport\Maintenance\ImportConstraintEntities->importEntityFromWikidata()
#6 /var/www/html/w/maintenance/includes/MaintenanceRunner.php(681): WikibaseQuality\ConstraintReport\Maintenance\ImportConstraintEntities->execute()
#7 /var/www/html/w/maintenance/run.php(51): MediaWiki\Maintenance\MaintenanceRunner->run()
#8 {main}

What should have happened instead?:

No errors

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

Other information (browser name/version, screenshots, etc.):

Event Timeline

Spent about 6 hours trying to solve this and was unable to.

Tried making the user in

$this->entityStore->saveEntity(
	$wikidataEntity,
	"imported from [[wikidata:$wikidataEntityId]]",
	$this->authority,
	EDIT_NEW | EDIT_FORCE_BOT
)->getEntity();

an UltimateAuthority

if ( !$this->getOption( 'dry-run', false ) ) {
	$this->user = User::newSystemUser( 'WikibaseQualityConstraints importer' );
	$this->authority = new UltimateAuthority( $this->user );
}

which is supposed to be used for maintenance scripts as it is allowed all permissions (isAllowed always returns true) so it will pass

private function toRateLimitSubject(): RateLimitSubject {
	$flags = [
		'exempt' => $this->isAllowed( 'noratelimit' ),
		'newbie' => $this->isNewbie(),
	];
	return new RateLimitSubject( $this, $this->getRequest()->getIP(), $flags );
}

and changed all associated methods to use an Authority instead of User but that didn't work because somehow MediaWiki creates a FauxRequest for the edit action somewhere in the code and the User for that FauxRequest is not the UltimateAuthority that was created so

public function getNewId( $type ) {
	if ( $this->contextSource->getUser()->pingLimiter( self::RATELIMIT_NAME ) ) {
		throw new StorageException( Status::newFatal( 'actionthrottledtext' ) );
	}

	return $this->idGenerator->getNewId( $type );
}

in RateLimitingIdGenerator ends up pinging the limiter.

Wikibase is too hard. Authority and User are too confusing.

@daniel probably knows how to solve this.