SemanticMediaWiki / SemanticResultFormats

Provides additional visualizations (result formats) for Semantic MediaWiki
https://www.semantic-mediawiki.org/wiki/Extension:Semantic_Result_Formats
Other
45 stars 75 forks source link

ParentProperties not shown with format=datatables #825

Closed jongfeli closed 2 months ago

jongfeli commented 3 months ago

Setup

Issue

Anything above SRF 4.0.2 will break to following query when the format=datatables is used. When there are multiple results it will show all the SubobjectProperties but only one or none of the ParentProperties:

{{#ask: [[YourSubobjectProperty1::SubobjectProperty]]
 |?-has subobject.YourParentProperty1
 |?-has subobject.YourParentProperty2
 |?YourSubobjectProperty2
 |format=datatables
}}

Steps to reproduce Made an example in the SMW sandbox but it is running SRF 4.0.2 so it is still working. See: https://sandbox.semantic-mediawiki.net/wiki/Subobject_In_Datatables

The result with 4.0.2: Datatables_Result_SRF_4 0 2

The result with SRF 4.2.1 would look something like this: Datatables_Result_SRF_4 2 1

Best regards,

Felipe.

jongfeli commented 3 months ago

Okay, after some debugging I found "the problem".

In DataTabels.php I moved $result = $this->getResultJson( $res, $outputmode ); to be above and before // @TODO use only one between printouts and printrequests

    $formattedOptions = $this->formatOptions( $datatablesOptions );

        $result = $this->getResultJson( $res, $outputmode );

        // @TODO use only one between printouts and printrequests
        $resultArray = $res->toArray();
        $printrequests = $resultArray['printrequests'];

        $this->useAjax = $this->query->getOption( 'useAjax' );

I am not sure if this is a correct fix or that it will cause other problems but now at least the outputted table is complete again.

gesinn-it-gea commented 3 months ago

ping @krabina @thomas-topway-it

thomas-topway-it commented 3 months ago

@jongfeli can you please try with the latest version of Datatables ? https://github.com/semanticMediaWiki/SemanticResultFormats --- we have merged it right 2 days ago. Thanks a lot

jongfeli commented 3 months ago

Hi @thomas-topway-it I downloaded the code but I still need to move $result = $this->getResultJson( $res, $outputmode ); to get it to work.

thomas-topway-it commented 3 months ago

ok, thank you, I will review it soon

hkwi commented 2 months ago

I run into the same problem, and looked into the code. QueryResult::toArray moves the QueryResult iterator cursor to the last position, and we should call QueryResult::reset at the to of getResultJson and then loop the QueryResult iterator.

Sorry, that was not correct. I looked into the code again, and wrote a patch SemanticMediaWiki/SemanticMediaWiki/pull/5623 , that should fix the problem...

thomas-topway-it commented 2 months ago

hello Iroaki, @hkwi I wanted to post that the idea about resetting the iterator was a great hint (anyway). So do you confirm that the provided patch fixes the issue, and that is not related to Datatables ?

hkwi commented 2 months ago

With noajax=true option, I confirmed the patch fixes the issue, that CHAIN property drops values.

Datatables plugin scans the QueryResult twice, while many plugins scan once. In the first scan, results are all filled, but in the second scan, cache is broken and values are lost. First scan will be triggerd by $res->toArray() and second is getResultJson(). We only capture the result part of toArray() output, so putting getResultJson() before toArray() shall be a good work-around anyway, IMHO.

krabina commented 2 months ago

@thomas-topway-it can you test the patch in our FINA wiki, so we can confirm everything is still working?

jaideraf commented 2 months ago

I have just came across this issue in my wiki, too.

jaideraf commented 2 months ago

@jongfeli please test the master version, it works for me now.

"mediawiki/semantic-result-formats": "dev-master",

jongfeli commented 2 months ago

@jaideraf, yes it is working just fine, thank you.