Page MenuHomePhabricator

Investigate if OR functionality results are working as expected or a bug
Closed, ResolvedPublic

Description

A user reported the following scenario:

I tried a query with multiple statements that are inside an "or"-block. This works when all of the statements return something, like here: https://doc.wikimedia.org/Wikibase/master/js/graphql-explorer/?query=cXVlcnkgc2VhcmNoSXRlbXMgewogIHNlYXJjaEl0ZW1zKAogICAgcXVlcnk6IHsKICAgICAgb3I6IFsKICAgICAgICB7IHByb3BlcnR5OiAiUDM3MyIsIHZhbHVlOiAiSGFtYnVyZyIgfSwKICAgICAgICB7IHByb3BlcnR5OiAiUDM3MyIsIHZhbHVlOiAiQmVybGluIiB9LAogICAgICBdCiAgICB9CiAgKSB7CiAgICBlZGdlcyB7CiAgICAgIG5vZGUgewogICAgICAgIGlkCiAgICAgICAgbGFiZWwobGFuZ3VhZ2VDb2RlOiAiZW4iKQogICAgICB9CiAgICB9CiAgfQp9

But when adding a single statement to the "or"-block that doesn't return a result, the whole result is empty. I would intuitively expect that the results of the other statements would be included in the result:

https://doc.wikimedia.org/Wikibase/master/js/graphql-explorer/?query=cXVlcnkgc2VhcmNoSXRlbXMgewogIHNlYXJjaEl0ZW1zKAogICAgcXVlcnk6IHsKICAgICAgb3I6IFsKICAgICAgICB7IHByb3BlcnR5OiAiUDM3MyIsIHZhbHVlOiAiSGFtYnVyZyIgfSwKICAgICAgICB7IHByb3BlcnR5OiAiUDM3MyIsIHZhbHVlOiAiQmVybGluIiB9LAogICAgICAgIHsgcHJvcGVydHk6ICJQMzczIiwgdmFsdWU6ICJkb2VzIG5vdCBleGlzdCIgfSwKICAgICAgXQogICAgfQogICkgewogICAgZWRnZXMgewogICAgICBub2RlIHsKICAgICAgICBpZAogICAgICAgIGxhYmVsKGxhbmd1YWdlQ29kZTogImVuIikKICAgICAgfQogICAgfQogIH0KfQ%3D%3D

They are unsure if this is a bug and if not, is there a way around it?

AC:

  • Figure out if this is expected behaviour or not
  • If this is expected behaviour, we should document this/the underlying logic properly or throw an appropriate error message if that's possible
  • If this is not expected behaviour, is it caused by the GraphQL API design or is caused due to the underlying CirrusSearch logic?
  • Fix underlying issue if it's in the API design - either by throwing an appropiate error or solving for it

Event Timeline

Change #1268850 had a related patch set uploaded (by Jakob; author: Jakob):

[mediawiki/extensions/Wikibase@master] GQL: Quote haswbstatement value in OR search

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

But when adding a single statement to the "or"-block that doesn't return a result, the whole result is empty.

I'm 99% sure that the problem isn't that one of the values can't be found, but rather that the value contains spaces. The example in the task description uses value: "does not exist", which doesn't find anything, but if we change that to value: "doesnotexist" (no spaces), it works as expected (explorer link). This is a bug that we can easily fix :)

Change #1268850 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] GQL: Quote haswbstatement value in OR search

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

This is fixed on beta wikidata now. Can be tried out using the following query:

{
  searchItems(
    query: {
      or: [
        { property: "P443", value: "potato" },
        { property: "P443", value: "does not exist" },
      ]
    }
  ) {
    edges {
      node { id }
    }
  }
}

Single-line curl command for the same query: curl --request POST --url 'https://www.wikidata.beta.wmcloud.org/w/api.php?action=wbgraphql&format=json' --header 'content-type: application/json' --data '{"query":"{ searchItems( query: { or: [ { property: \"P443\", value: \"potato\" }, { property: \"P443\", value: \"does not exist\" } ] } ) { edges { node { id } } } }"}'