Fix filtered format multiple srf filtered config - #1052
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1052 +/- ##
============================================
- Coverage 52.88% 52.86% -0.03%
- Complexity 2439 2440 +1
============================================
Files 81 81
Lines 9281 9283 +2
============================================
- Hits 4908 4907 -1
- Misses 4373 4376 +3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
krabina
left a comment
There was a problem hiding this comment.
I cannot comment on the code, but this PR fixed the problem we encountered.
|
Reviewed and verified locally against a real MediaWiki + Semantic MediaWiki instance. Root cause confirmed: this regressed in 6169690 (24 Apr 2026, "clarify RequestContext fallback and fix missing JS config var"), which replaced The fix here is correct: moving the I wrote and verified a regression test reproducing the exact crash from #1039 (two <?php
namespace SRF\Tests\Filtered;
use MediaWikiIntegrationTestCase;
use SRF\Filtered\Filtered;
use SRF\Filtered\Hooks;
/**
* Regression test for https://github.com/SemanticMediaWiki/SemanticResultFormats/issues/1039
*
* When a page contains more than one {{#ask:format=filtered}} instance, each instance
* used to call ParserOutput::setJsConfigVar( 'srfFilteredConfig', $accumulatedConfig )
* with a different array value for the same key, which MediaWiki core rejects with
* "Multiple conflicting values given for srfFilteredConfig" (InvalidArgumentException).
*
* @covers \SRF\Filtered\Filtered
* @covers \SRF\Filtered\Hooks
* @group semantic-result-formats
*/
class MultipleFilteredInstancesTest extends MediaWikiIntegrationTestCase {
private function addConfigToOutput( Filtered $printer, $id, array $config ) {
$method = new \ReflectionMethod( Filtered::class, 'addConfigToOutput' );
$method->setAccessible( true );
$method->invoke( $printer, $id, $config );
}
public function testTwoFilteredInstancesOnSamePage_doNotThrow() {
$parserOutput = new \ParserOutput();
$parser = $this->createMock( \Parser::class );
$parser->method( 'getOutput' )->willReturn( $parserOutput );
$firstInstance = new Filtered( null );
$firstInstance->setParser( $parser );
$secondInstance = new Filtered( null );
$secondInstance->setParser( $parser );
// Simulate two independent #ask calls with format=filtered on the same page.
$this->addConfigToOutput( $firstInstance, 'filtered-1', [ 'views' => [ 'list' ] ] );
$this->addConfigToOutput( $secondInstance, 'filtered-2', [ 'views' => [ 'table' ] ] );
$mergedConfig = $parserOutput->getExtensionData( 'srf-filtered-config' );
$this->assertSame(
[
'filtered-1' => [ 'views' => [ 'list' ] ],
'filtered-2' => [ 'views' => [ 'table' ] ],
],
$mergedConfig
);
// This is the call that used to throw InvalidArgumentException before the fix,
// because Filtered::addConfigToOutput no longer calls setJsConfigVar() directly.
$outputPage = new \OutputPage( \RequestContext::getMain() );
Hooks::onOutputPageParserOutput( $outputPage, $parserOutput );
$this->assertSame( $mergedConfig, $outputPage->getProperty( 'srf-filtered-config' ) );
$this->assertSame( $mergedConfig, $outputPage->getJsConfigVars()['srfFilteredConfig'] );
}
}Place at
One small nit unrelated to correctness: |
|
@thomas-topway-it would you like to add the test before merge? |
$parserOutput->setJsConfigVartoonOutputPageParserOutputhook, othwewise if the page contains multiple filtered instances MW'sParserOutputwill raise an error)