SemanticMediaWiki / SemanticScribunto

Provides service functions to support the Scribunto extension
Other
24 stars 14 forks source link

ask and getQueryResult fail on format=debug #25

Closed oetterer closed 7 years ago

oetterer commented 7 years ago

Setup and configuration

Issue

Since \SMW\Scribunto\LibraryFactory::newQueryResultFrom does not return an object of class \SMWQueryResult on format=debug, function ask fails in \SMW\Scribunto\LuaAskResultProcessor::__construct

Stacktrace is:

1) LuaSandbox: SMW\Scribunto\Tests\ScribuntoLuaLibraryAskTest[5]: ask (format debug)
Argument 1 passed to SMW\Scribunto\LuaAskResultProcessor::__construct() must be an instance of SMWQueryResult, string given, called in /var/www/luasmw/mediawiki-1.27.1/extensions/SemanticScribunto.github/src/LibraryFactory.php on line 71 and defined

/var/www/luasmw/mediawiki-1.27.1/extensions/SemanticScribunto.github/src/LuaAskResultProcessor.php:48
/var/www/luasmw/mediawiki-1.27.1/extensions/SemanticScribunto.github/src/LibraryFactory.php:71
/var/www/luasmw/mediawiki-1.27.1/extensions/SemanticScribunto.github/src/ScribuntoLuaLibrary.php:66
/var/www/luasmw/mediawiki-1.27.1/extensions/Scribunto/engines/LuaSandbox/Engine.php:403
/var/www/luasmw/mediawiki-1.27.1/extensions/Scribunto/engines/LuaSandbox/Engine.php:316
/var/www/luasmw/mediawiki-1.27.1/extensions/Scribunto/tests/engines/LuaCommon/LuaDataProvider.php:49
/var/www/luasmw/mediawiki-1.27.1/extensions/Scribunto/tests/engines/LuaCommon/LuaEngineTestBase.php:244
/var/www/luasmw/mediawiki-1.27.1/tests/phpunit/MediaWikiTestCase.php:156

and getQueryResult fails in \SMW\Scribunto\ScribuntoLuaLibrary::getQueryResult on operation

  $result = $queryResult->toArray();

with

PHP Fatal error:  Call to a member function toArray() on string in /var/www/luasmw/mediawiki-1.27.1/extensions/SemanticScribunto.github/src/ScribuntoLuaLibrary.php on line 119

Reproduction

Steps to reproduce the observation (recommendation is to use the sandbox):

I added the tests

{ name = 'ask (format debug)', func = mw.smw.ask,
    args = { { '[[Modification date::+]]', '?Modification date', limit = 2, mainlabel = 'main', format = 'debug' } },
    expect = { nil }
},
{ name = 'getQueryResult (format debug)', func = mw.smw.getQueryResult,
    args = { { '[[Modification date::+]]', '?Modification date', limit = 2, mainlabel = 'main', format = 'debug' } },
    expect = { nil }
}

note

mwjames commented 7 years ago

Neither \SMW\Store::getQueryResult nor \SMW\Scribunto\LibraryFactory::newQueryResultFrom documents this possible behavior correctly

I know it's a bit unfair but [0] does mention @return QueryResult|string.

[0] https://github.com/SemanticMediaWiki/SemanticMediaWiki/blob/master/src/QueryEngine.php

oetterer commented 7 years ago

@mwjames touché :)