Page MenuHomePhabricator

Sparql queries using optional patterns produce an error
Closed, ResolvedPublic

Description

My wiki page has an embedded SPARQL query like the following:

{{#sparql:
prefix pdmm: <http://example.com/bla#>
select distinct ?dataModelEntity ?desc where {
  <{{{uri}}}> pdmm:hasRelatedClass ?dataModelEntity .
  optional {
    ?dataModelEntity pdmm:shortDescription ?desc .
    filter(lang(?desc) = "en") .
  }
}
 |headers=Data Model Element, Description
 |classHeaders= class="text-nowrap"
 |templates=SystemInterfaceRelation,
 |footer=NO
}}

As long as each result row has a value for "?desc" all is fine. However, as soon as one result does not include a value for "?desc" I get the following error on the Wiki page:

Notice: Undefined index: desc in /opt/app-root/src/php/w/extensions/LinkedWiki/parser/SparqlParser.php on line 254

The rest of the page will still render but the error message is there.

Some versioning info:

  • Mediawiki: 1.32.0
  • Skin: Tweeki 1.1.0
  • Sem MW: 3.0.2
  • LinkedWiki: 3.2.0

Event Timeline

Karima subscribed.

@Truegeex You can use this quick fix with BOUND and BIND for the moment :

select distinct ?dataModelEntity ?desc where {
  <{{{uri}}}> pdmm:hasRelatedClass ?dataModelEntity .
  optional {
    ?dataModelEntity pdmm:shortDescription ?descOptional .
    filter(lang(?descOptional) = "en") .
  }
  BIND (IF( BOUND(?descOptional), ?descOptional, "")  AS ?desc)
}

At the next version, I will fix this problem.
Thanks

Thank you. That is great news. Do you know of any workaround until then?

Oh, sorry, you already provided that. :D
Brilliant support. Thanks again.

Sadly I get the same error with your workaround: "Undefined index: desc".

Sadly I get the same error with your workaround: "Undefined index: desc".

@Truegeex Can you show your query ? Can I test on your wiki ? may be replace "" by "&nbsp;" in the query...

Sadly my wiki is running in a company intranet which I cannot give you access to. But your suggestion worked! Binding to "&nbsp;" did the trick! Thanks again!