Page MenuHomePhabricator

Revision with ID not found.
Closed, ResolvedPublicBUG REPORT

Description

Steps to replicate the issue (include links if applicable):

  • Create a new wikidata item through the REST API with at least one statement.
  • Attempt to modify or remove the statement in the newly created item.
  • Upon submission, receive the error Revision with ID not found.

What happens?:

It's not possible to remove or modify statements for a new Wikidata item created through the REST API.

What should have happened instead?:

The statement should be removed or updated when modified as is the case for a manually created item.

Software version (on Special:Version page; skip for WMF-hosted wikis like Wikipedia):

Other information (browser name/version, screenshots, etc.):

Firefox 148.0.2

Wikidata items where this problem can be seen:

Curl command used to create the items:

`curl -X 'POST' \

'https://www.wikidata.org/w/rest.php/wikibase/v1/entities/items' \
--header 'accept: application/json' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer '$WIKIDATA_ACCESS_TOKEN \
--header 'X-Authenticated-User: '$WIKIDATA_USERNAME \
-d @payload.json`

I can attach the JSON payload file(s) if needed.

Event Timeline

I reused data from an item I retrieved using the REST API. I bet the problem is from reusing the Wikidata id's with what is perhaps a revision number at the end? The submissions had ids like this:

"id": "Q138961839$d93acd49-4bbd-4c82-b686-a28c2ae0d68f"

I figured it out. Those are statement IDs. I was including the statement ids from a REST API response when creating a new item. Removing those IDs from the payload fixes the problem. I can now create items and the statements are editable as expected.

Alright, then I guess we can close this.

I imagine other people will make this mistake, and it results in completely broken statements which can't be fixed by the user. The API needs to ensure this doesn't happen in the future. The existing statements in Wikidata items Q138974096 and Q138975112 are still completely broken and can't be edited or removed by users.

Okay, that’s wild.

image.png (269×876 px, 24 KB)

Yes, please attach your JSON payload, we definitely want to know how you managed to create these statements…

aaaaaa the statement ID contains the item ID of a different item than this one

image.png (208×535 px, 27 KB)

why does the REST API allow this /o\

aaaaaa the statement ID contains the item ID of a different item than this one

image.png (208×535 px, 27 KB)

why does the REST API allow this /o\

Yep! That's exactly it. I should have made that clear in my update. Since it is a new item, it won't have a Wikidata item id yet but you can still put one in.

Uploaded the payload for reference:

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

[mediawiki/extensions/Wikibase@master] CRUD: Ensure IDs of new statements are ignored

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

Change #1269098 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] CRUD: Ensure IDs of new statements are ignored

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

Regarding broken statements on Items like Q138974096, we see several ways to fix them via API, even by users.

Option 1) Using the PATCH method in REST API, by sending this request to https://www.wikidata.org/w/rest.php/wikibase/v1/entities/items/Q138974096:

{
  "patch": [
    {
      "op": "remove",
      "path": "/statements/P31/0/id"
    }
  ]
}

This will remove the invalid statement ID and automatically create a new valid one. Multiple remove operations can be sent in a single request.

Option 2) Using the Action API, by getting the entity json, manually replacing the incorrect item ID prefixes in the statement IDs, then saving it using wbeditentity with the clear parameter enabled (i.e. replace the whole entity).

@jwillikers Please let us know here whether you are comfortable applying the fixes or if you’d prefer us to do it.

Regarding broken statements on Items like Q138974096, we see several ways to fix them via API, even by users.

Option 1) Using the PATCH method in REST API, by sending this request to https://www.wikidata.org/w/rest.php/wikibase/v1/entities/items/Q138974096:

{
  "patch": [
    {
      "op": "remove",
      "path": "/statements/P31/0/id"
    }
  ]
}

This will remove the invalid statement ID and automatically create a new valid one. Multiple remove operations can be sent in a single request.

Option 2) Using the Action API, by getting the entity json, manually replacing the incorrect item ID prefixes in the statement IDs, then saving it using wbeditentity with the clear parameter enabled (i.e. replace the whole entity).

@jwillikers Please let us know here whether you are comfortable applying the fixes or if you’d prefer us to do it.

@Silvan_WMDE Thanks for the instructions! I've take care of that for Q138974096 and Q138975112 and they are editable again. Thanks again!

@Silvan_WMDE Thanks for the instructions! I've take care of that for Q138974096 and Q138975112 and they are editable again. Thanks again!

\o/