Page MenuHomePhabricator

Save a statement with a federated property when Federation v2 is enabled
Open, HighPublic8 Estimated Story Points

Description

As a Wikibase editor in a wiki with Federated Properties enabled, I want to be able to add statements to local items using both local and remote properties so that I can combine my local ontology with a remote ontology.

Right now saving a statement containing a federated property fails because the ID expects something that looks like a local property ID (i.e. P1234).

The request to the api should look like:

action=wbsetclaim&format=json&claim=%7B%22type%22%3A%22statement%22%2C%22mainsnak%22%3A%7B%22snaktype%22%3A%22value%22%2C%22property%22%3A%22http%3A%2F%2Fwikidata.beta.wmflabs.org%2Fentity%2FP93%22%2C%22datavalue%22%3A%7B%22type%22%3A%22string%22%2C%22value%22%3A%22cat%22%7D%7D%2C%22id%22%3A%22Q5%2468a44a9f-4be9-5913-686a-316797a20985%22%2C%22rank%22%3A%22normal%22%7D&baserevid=15&bot=1&assertuser=WikibaseAdmin&errorformat=plaintext&uselang=en&token=a95e1e659ccf1980cec8f239c87bac7461138d34%2B%5C

The users facing error looks like:

image.png (362×1 px, 41 KB)

and the api error reads:

{"errors":[{"code":"internal_api_error_InvalidArgumentException","data":{"errorclass":"InvalidArgumentException"},"*":"[8db27d21c5441bfe65b464de] Exception caught: $idSerialization must match /^P[1-9]\\d{0,9}\\z/i"}],"*":"InvalidArgumentException at /var/www/html/vendor/wikibase/data-model/src/Entity/PropertyId.php(34)\nfrom /var/www/html/vendor/wikibase/data-model/src/Entity/PropertyId.php(34)\n#0 /var/www/html/vendor/wikibase/data-model/src/Entity/PropertyId.php(26): Wikibase\\DataModel\\Entity\\PropertyId->assertValidIdFormat(string)\n#1 /var/www/html/extensions/Wikibase/lib/includes/Serialization/CallbackFactory.php(74): Wikibase\\DataModel\\Entity\\PropertyId->__construct(string)\n#2 /var/www/html/extensions/Wikibase/lib/includes/Serialization/SerializationModifier.php(70): Wikibase\\Lib\\Serialization\\CallbackFactory->Wikibase\\Lib\\Serialization\\{closure}(array)\n#3 /var/www/html/extensions/Wikibase/lib/includes/Serialization/SerializationModifier.php(63): Wikibase\\Lib\\Serialization\\SerializationModifier->modifyUsingUnflattenedCallbacks(array, array)\n#4 /var/www/html/extensions/Wikibase/lib/includes/Serialization/SerializationModifier.php(33): Wikibase\\Lib\\Serialization\\SerializationModifier->modifyUsingUnflattenedCallbacks(array, array)\n#5 /var/www/html/extensions/Wikibase/repo/includes/Api/ResultBuilder.php(908): Wikibase\\Lib\\Serialization\\SerializationModifier->modifyUsingCallbacks(array, array)\n#6 /var/www/html/extensions/Wikibase/repo/includes/Api/ResultBuilder.php(881): Wikibase\\Repo\\Api\\ResultBuilder->getArrayWithAlteredClaims(array)\n#7 /var/www/html/extensions/Wikibase/repo/includes/Api/SetClaim.php(211): Wikibase\\Repo\\Api\\ResultBuilder->addStatement(Wikibase\\DataModel\\Statement\\Statement)\n#8 /var/www/html/extensions/Wikibase/repo/includes/Api/SetClaim.php(162): Wikibase\\Repo\\Api\\SetClaim->executeInternal()\n#9 /var/www/html/includes/api/ApiMain.php(1842): Wikibase\\Repo\\Api\\SetClaim->execute()\n#10 /var/www/html/includes/api/ApiMain.php(821): ApiMain->executeAction()\n#11 /var/www/html/includes/api/ApiMain.php(792): ApiMain->executeActionWithErrorHandling()\n#12 /var/www/html/api.php(90): ApiMain->execute()\n#13 /var/www/html/api.php(45): wfApiMain()\n#14 {main}"}

BDD Scenario: On an entity page in a Wikibase with Federated Properties enabled
GIVEN I am adding a statement to a local entity containing a federated property
WHEN I click Save
THEN I can view valid entity JSON from Special:EntityData/Q1.json

Event Timeline

Until this is done we don't know if any work needs to be done to render an Entity page containing a statement using a federated property.

From task breakdown:

  • needs to use an EntityIdParser in CallbackFactory::getCallbackToAddDataTypeToSnaksGroupedByProperty and CallbackFactory::getCallbackToAddDataTypeToSnak
  • inject EntityIdParser into these two methods
  • likely needs EntityIdParser injected down from ApiResultBuilder
  • add an integration test

Maybe create a ticket for broken Property ID formatting after saving (UI?).

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

[mediawiki/extensions/WikibaseLexeme@master] FP: add EntityIdParser to API ResultBuilder

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

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

[mediawiki/extensions/Wikibase@master] FP: use EntityIdParser in CallbackFactory

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

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

[mediawiki/extensions/Wikibase@master] FP: remove EntityIdParser related compat code

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

Change 716232 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] FP: use EntityIdParser in CallbackFactory

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

Change 716231 merged by jenkins-bot:

[mediawiki/extensions/WikibaseLexeme@master] FP: add EntityIdParser to API ResultBuilder

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

Change 716298 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] FP: remove EntityIdParser related compat code

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

This is verified, but I did find that upon save, the remote property is not displayed with the appropriate label (seen in screenshot below) until I refresh the page. Will file a bug.

image.png (447×1 px, 52 KB)