Page MenuHomePhabricator

[ES-M2]: Updating EntitySchema to make use of the new mechanism
Closed, ResolvedPublic

Description

To make use of the new mechanism implemented in the patch from the Product Platform team, we need to make some changes on the EntitySchema side.

When parsing statement/qualifier/reference values, Wikibase will take into account the corresponding Property's data type and not only the value type. A data type specific value parser can be registered with the data type definition (here: EntitySchema). This will allow serialized EntitySchema values to contain type: wikibase-entityid without being parsed as an EntityIdValue.

The changes that are required are:

  • New value type
  • New parser/deserializer
  • Adjust validators

Acceptance criteria

  • Users are able to create an EntitySchema data value type statement
  • Users are able to load an EntitySchema data value type statement and it is linked to the EntitySchema

To create a statement using the API sandbox, use the wbsetclaim action, let the API sandbox fill in the token parameter, and set the claim to JSON similar to this:

{"type":"statement","mainsnak":{"snaktype":"value","property":"P592","datavalue":{"type":"wikibase-entityid","value":{"id":"E1"}}},"id":"P592$6dcf36c9-238a-435b-8ead-6fd1915b8548","rank":"normal"}

Where P592 is a property with data type EntitySchema, 6dcf36c9-238a-435b-8ead-6fd1915b8548 is a random UUID (you can get a fresh one from cat /proc/sys/kernel/random/uuid), and E1 is the ID of an existing EntitySchema.

Event Timeline

@Lucas_Werkmeister_WMDE can you please add the info for the API sandbox?

To make use of the new mechanism implemented in the patch from the Product Platform team

I’m trying to figure out what the status of that mechanism is… the relevant tasks seem to be T354778 and T359421, and the big change adding the new mechanism (corresponding to the prototype changes in T355144) seems to be Wire up DataTypeAwareSnakDeserializer.

Change #994206 had a related patch set uploaded (by Arthur taylor; author: Jakob):

[mediawiki/extensions/EntitySchema@master] Use custom entity schema value parser

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

Change #1007655 had a related patch set uploaded (by Arthur taylor; author: Jakob):

[mediawiki/extensions/EntitySchema@master] Register entity schema data type for clients

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

Change #1023082 had a related patch set uploaded (by Arthur taylor; author: Arthur taylor):

[mediawiki/extensions/EntitySchema@master] Add formatting for EntitySchema values

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

Change #994206 merged by jenkins-bot:

[mediawiki/extensions/EntitySchema@master] Use custom entity schema value parser

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

Change #1007655 merged by jenkins-bot:

[mediawiki/extensions/EntitySchema@master] Register entity schema data type for clients

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

Change #1023082 merged by jenkins-bot:

[mediawiki/extensions/EntitySchema@master] Add formatting for EntitySchema values

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

Tried to test this on beta now with:

{"type":"statement","mainsnak":{"snaktype":"value","property":"P253077","datavalue":{"type":"wikibase-entityid","value":{"id":"E10"}}},"id":"P253077$96461d0e-06dd-11ef-9fbf-8b25ca3a3caf","rank":"normal"}

I get the message that my user doesn't have permission to make edits in the property namespace:

{
    "error": {
        "code": "failed-save",
        "info": "The save has failed.",
        "messages": [
            {
                "name": "wikibase-api-failed-save",
                "parameters": [],
                "html": "The save has failed."
            },
            {
                "name": "namespaceprotected",
                "parameters": [
                    "Property",
                    "edit"
                ],
                "html": "You do not have permission to edit pages in the <strong>Property</strong> namespace."
            },
            {
                "name": "permissionserrors",
                "parameters": [],
                "html": "Permission error"
            }
        ],
        "docref": "See https://wikidata.beta.wmflabs.org/w/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at &lt;https://lists.wikimedia.org/postorius/lists/mediawiki-api-announce.lists.wikimedia.org/&gt; for notice of API deprecations and breaking changes."
    },
    "servedby": "deployment-mediawiki11"
}

@Lucas_Werkmeister_WMDE do you have permission?

[…]
I get the message that my user doesn't have permission to make edits in the property namespace:
[…]
@Lucas_Werkmeister_WMDE do you have permission?

You can just try the edit on an item, by changing the claim's "id", eg. to Q584208$6dcf36c9-238a-435b-8ead-6fd1915b8548 to edit item Q584208. Also I made you an administrator on beta Wikidata now… while not needed here, it could come in handy sometime.

I submitted an edit with the same statement (on a different entity) and got:

{
	"error": {
		"code": "modification-failed",
		"info": "Data value corrupt: Can not parse id 'E1' to build EntityIdValue with",
		"messages": [
			{
				"name": "wikibase-validator-bad-value",
				"parameters": [
					"Can not parse id 'E1' to build EntityIdValue with"
				],
				"html": {
					"*": "Data value corrupt: Can not parse id 'E1' to build EntityIdValue with"
				}
			}
		],
		"*": "See https://wikidata.beta.wmflabs.org/w/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at &lt;https://lists.wikimedia.org/postorius/lists/mediawiki-api-announce.lists.wikimedia.org/&gt; for notice of API deprecations and breaking changes."
	}
}

Tested the same on my local using the code that's on master and it seems to work for me:

{"type":"statement","mainsnak":{"snaktype":"value","property":"P16","datavalue":{"type":"wikibase-entityid","value":{"id":"E31"}}},"id":"P16$96461d0e-06dd-11ef-9fbf-8b25ca3a3caf","rank":"normal"}
{
    "pageinfo": {
        "lastrevid": 397
    },
    "success": 1,
    "claim": {
        "mainsnak": {
            "snaktype": "value",
            "property": "P16",
            "hash": "06373dc2cba29042f40ce013476d88e9eebcd3d3",
            "datavalue": {
                "value": {
                    "id": "E31",
                    "type": "entityschema"
                },
                "type": "wikibase-entityid"
            },
            "datatype": "entity-schema"
        },
        "type": "statement",
        "id": "P16$96461d0e-06dd-11ef-9fbf-8b25ca3a3caf",
        "rank": "normal"
    },
    "tempusercreated": "~2024-2",
    "tempuserredirect": "http://wikidatawikidev.mediawiki.mwdd.localhost:8080/w/index.php?title=Main_Page&redirected-by-hook=yes"
}

I will see if I can find out why beta is behaving differently.

Now that @hoo granted my admin permission, the request works as expected:

{"type":"statement","mainsnak":{"snaktype":"value","property":"P253077","datavalue":{"type":"wikibase-entityid","value":{"id":"E10"}}},"id":"P253077$96461d0e-06dd-11ef-9fbf-8b25ca3a3caf","rank":"normal"}
{
    "pageinfo": {
        "lastrevid": 1357755
    },
    "success": 1,
    "claim": {
        "mainsnak": {
            "snaktype": "value",
            "property": "P253077",
            "hash": "dfd9d283e690f43d8710a2367e52b989a73ea5d7",
            "datavalue": {
                "value": {
                    "id": "E10",
                    "type": "entityschema"
                },
                "type": "wikibase-entityid"
            },
            "datatype": "entity-schema"
        },
        "type": "statement",
        "id": "P253077$96461d0e-06dd-11ef-9fbf-8b25ca3a3caf",
        "rank": "normal"
    }
}

and the property is linked to the entity-schema. I assume the reason that Marius' request failed is that we only have the Data Type Definition present for a Property Type of entity-schema - there's no Value Type registration.

Creating an entity schema statement on an item worked fine for me.

https://wikidata.beta.wmflabs.org/wiki/Special:ApiSandbox#action=wbcreateclaim&format=json&entity=Q11&snaktype=value&property=P253077&value=%7B%22id%22%3A%22E10%22%7D&formatversion=2

Response:

{
    "pageinfo": {
        "lastrevid": 1357759
    },
    "success": 1,
    "claim": {
        "mainsnak": {
            "snaktype": "value",
            "property": "P253077",
            "hash": "dfd9d283e690f43d8710a2367e52b989a73ea5d7",
            "datavalue": {
                "value": {
                    "id": "E10",
                    "type": "entityschema"
                },
                "type": "wikibase-entityid"
            },
            "datatype": "entity-schema"
        },
        "type": "statement",
        "id": "Q11$E4C0098F-386E-4D1B-BA4E-EA6F841FF489",
        "rank": "normal"
    }
}

Not sure what went wrong in T362001#9757950 - wrong property id maybe?

[…]

Not sure what went wrong in T362001#9757950 - wrong property id maybe?

I just double checked and yes, that's it: P592 has data type string. Sorry for the confusion.

Change #1031928 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/extensions/EntitySchema@master] Make EntitySchemaValue::getArrayValue() match EntityIdValue

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

Change #1031928 merged by jenkins-bot:

[mediawiki/extensions/EntitySchema@master] Make EntitySchemaValue::getArrayValue() match EntityIdValue

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

Change #1032429 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/extensions/EntitySchema@wmf/1.43.0-wmf.5] Make EntitySchemaValue::getArrayValue() match EntityIdValue

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

Change #1032430 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/extensions/EntitySchema@wmf/1.43.0-wmf.4] Make EntitySchemaValue::getArrayValue() match EntityIdValue

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

Change #1032429 merged by jenkins-bot:

[mediawiki/extensions/EntitySchema@wmf/1.43.0-wmf.5] Make EntitySchemaValue::getArrayValue() match EntityIdValue

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

Change #1032430 merged by jenkins-bot:

[mediawiki/extensions/EntitySchema@wmf/1.43.0-wmf.4] Make EntitySchemaValue::getArrayValue() match EntityIdValue

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

Mentioned in SAL (#wikimedia-operations) [2024-05-16T13:47:53Z] <jsn@deploy1002> Started scap: Backport for [[gerrit:1032429|Make EntitySchemaValue::getArrayValue() match EntityIdValue (T362955 T362001)]], [[gerrit:1032430|Make EntitySchemaValue::getArrayValue() match EntityIdValue (T362955 T362001)]]

Mentioned in SAL (#wikimedia-operations) [2024-05-16T13:50:23Z] <jsn@deploy1002> jsn and lucaswerkmeister-wmde: Backport for [[gerrit:1032429|Make EntitySchemaValue::getArrayValue() match EntityIdValue (T362955 T362001)]], [[gerrit:1032430|Make EntitySchemaValue::getArrayValue() match EntityIdValue (T362955 T362001)]] synced to the testservers (https://wikitech.wikimedia.org/wiki/Mwdebug)

Mentioned in SAL (#wikimedia-operations) [2024-05-16T14:04:05Z] <jsn@deploy1002> Finished scap: Backport for [[gerrit:1032429|Make EntitySchemaValue::getArrayValue() match EntityIdValue (T362955 T362001)]], [[gerrit:1032430|Make EntitySchemaValue::getArrayValue() match EntityIdValue (T362955 T362001)]] (duration: 16m 11s)

Arian_Bozorg claimed this task.

This looks good to me :)