Page MenuHomePhabricator

TypeError: SecurePollContentHandler::makeContentFromElection(): Argument #1 ($election) must be of type Election, bool given (can't create elections on localhost if $wgSecurePollUseNamespace is turned on)
Closed, ResolvedPublicBUG REPORT

Description

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

  • on your localhost wiki...
$wgSecurePollUseNamespace = true;
  • make sure you are using 1 mariadb server, not 2
  • give yourself election admin
  • Visit Special:SecurePoll/create
  • Create a poll

What happens?:

  • PHP TypeError
[2437ea5fae22cb9cb5c640a8] /wiki/Special:SecurePoll/create TypeError: MediaWiki\Extension\SecurePoll\SecurePollContentHandler::makeContentFromElection(): Argument #1 ($election) must be of type MediaWiki\Extension\SecurePoll\Entities\Election, bool given, called in /var/www/html/w/extensions/SecurePoll/includes/Pages/CreatePage.php on line 914

Backtrace:

from /var/www/html/w/extensions/SecurePoll/includes/SecurePollContentHandler.php(161)
#0 /var/www/html/w/extensions/SecurePoll/includes/Pages/CreatePage.php(914): MediaWiki\Extension\SecurePoll\SecurePollContentHandler::makeContentFromElection()
#1 /var/www/html/w/extensions/SecurePoll/includes/Pages/CreatePage.php(893): MediaWiki\Extension\SecurePoll\Pages\CreatePage->recordElectionToNamespace()
#2 [internal function]: MediaWiki\Extension\SecurePoll\Pages\CreatePage->processInput()
#3 /var/www/html/w/includes/htmlform/HTMLForm.php(822): call_user_func()
#4 /var/www/html/w/includes/htmlform/HTMLForm.php(703): MediaWiki\HTMLForm\HTMLForm->trySubmit()
#5 /var/www/html/w/extensions/SecurePoll/includes/Pages/CreatePage.php(541): MediaWiki\HTMLForm\HTMLForm->tryAuthorizedSubmit()
#6 /var/www/html/w/extensions/SecurePoll/includes/SpecialSecurePoll.php(65): MediaWiki\Extension\SecurePoll\Pages\CreatePage->execute()
#7 /var/www/html/w/includes/specialpage/SpecialPage.php(728): MediaWiki\Extension\SecurePoll\SpecialSecurePoll->execute()
#8 /var/www/html/w/includes/specialpage/SpecialPageFactory.php(1726): MediaWiki\SpecialPage\SpecialPage->run()
#9 /var/www/html/w/includes/actions/ActionEntryPoint.php(504): MediaWiki\SpecialPage\SpecialPageFactory->executePath()
#10 /var/www/html/w/includes/actions/ActionEntryPoint.php(146): MediaWiki\Actions\ActionEntryPoint->performRequest()
#11 /var/www/html/w/includes/MediaWikiEntryPoint.php(200): MediaWiki\Actions\ActionEntryPoint->execute()
#12 /var/www/html/w/index.php(58): MediaWiki\MediaWikiEntryPoint->run()
#13 {main}

What should have happened instead?:

  • election is successfully created

Software version (on Special:Version page; skip for WMF-hosted wikis like Wikipedia):

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

Event Timeline

Right after creating a new election (I see the new election in my SQL database), this code path is reached:

		if ( $this->specialPage->getConfig()->get( 'SecurePollUseNamespace' ) ) {
			// Create a new context to bypass caching.
			$context = new Context;
			// We may be inside a transaction, so force a primary DB connection (T209804)
			$context->getStore()->setForcePrimary( true );

			$election = $context->getElection( $eId );

$wgSecurePollUseNamespace is true, so that conditional gets entered. An attempt is made to bypass the cache and to use a primary DB connection. Then an attempt is made to grab this election's data from cache. But $context->getElection( $eId ); returns false -- it is unable to grab the data.

Is there something going wrong with caching here?

Step debugging reveals this codepath:

image.png (532×1 px, 59 KB)

I get the same error as well when $wgSecurePollUseNamespace is true. Using MariaDb in local.

Looks like the issue was previously seen in production and fixed with T209804 - which made it use the primary db. Surprising that it would occur on local where there is only one db.

Change #1092298 had a related patch set uploaded (by SD0001; author: SD0001):

[mediawiki/extensions/SecurePoll@master] Avoid db read-after-write contention while logging to namespace

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

Change #1140776 had a related patch set uploaded (by Novem Linguae; author: Novem Linguae):

[mediawiki/extensions/SecurePoll@master] remove setForcePrimary()

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

Novem_Linguae renamed this task from TypeError: SecurePollContentHandler::makeContentFromElection(): Argument #1 ($election) must be of type Election, bool given to TypeError: SecurePollContentHandler::makeContentFromElection(): Argument #1 ($election) must be of type Election, bool given (can't create elections on localhost if $wgSecurePollUseNamespace is turned on).May 2 2025, 6:58 PM
Novem_Linguae updated the task description. (Show Details)

Change #1140781 had a related patch set uploaded (by Máté Szabó; author: Máté Szabó):

[mediawiki/extensions/SecurePoll@master] CreatePageTest: Add test for log page creation

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

Change #1092298 merged by jenkins-bot:

[mediawiki/extensions/SecurePoll@master] Avoid db read-after-write contention while logging to namespace

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

Change #1140781 merged by jenkins-bot:

[mediawiki/extensions/SecurePoll@master] CreatePageTest: Add test for log page creation

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

Novem_Linguae assigned this task to SD0001.

Change #1140776 merged by jenkins-bot:

[mediawiki/extensions/SecurePoll@master] remove setForcePrimary()

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