Page MenuHomePhabricator

๐Ÿฆž Modify data of descriptions of an item
Closed, ResolvedPublic13 Estimated Story Points

Description

As a tool builder I want to be able to change descriptions of an item so that work in my tool can be saved back to Wikidata.

PATCH /entities/items/{item_id}/descriptions

Acceptance criteria:

  • Request includes a JSON Patch document describing wanted changes

client can provide additional edit metadata: mediawiki tags, edit summary text to append to the automated summary, and a bot edit flag, like in PATCH /entities/items/{item_id}/statements/{statement_id}

  • Response to a success request will include the new statement data, inclduing the ETag (revision ID) and modification timestamp
  • "Automated edit summary" related to the edit to be of form: /* wbeditentity-update-languages-short:0||LANGS */ (similar to patching labels of items)
  • Handle HTTP conditional request headers as in PATCH /entities/items/{item_id}/labels
  • Handle user authentication/authorization like in PATCH /entities/items/{item_id}/labels

Error cases to consider:

error type HTTP Response codeResponse content
item with the given ID does not exist404"code": "item-not-found",
"message": "Could not find an item with the ID: '{item_id}'"
ID provided is not a valid item ID400 "code": "invalid-item-id",
"message": "Not a valid item ID: '{item_id}'"
Item with the provided ID has been redirected to another item409"code": "redirected-item"
"message": "Item {item_id} has been merged into {other_id}."
Invalid JSON patch (general error)400"code": "invalid-patch"
"message": "The provided patch is invalid"
incorrect JSON patch operation400"code": "invalid-patch-operation"
"message": "Incorrect JSON patch operation: '<op>'"
"context": { "operation": <operation_object> }
invalid field type in JSON patch
(either of op, path, from is not a string)
400"code": "invalid-patch-field-type"
"message": "The value of '<field>' must be of type string"
"context": { "operation": <operation_object>, "field": <field> }
missing mandatory field in JSON patch
(op, path, value, also from on copy/move patches)
400"code": "missing-json-patch-field"
"message": "Missing '<field>' in JSON patch"
"context": { "operation": <operation_object>, "field": <field> }
Target of JSON Patch not found on the object409"code": "patch-target-not-found",
"message": "Target '<target>' not found on the resource",
"context": {
"operation": <operation_object>,
"field": <path>
}
JSON Patch test operation failed409"code": "patch-test-failed",
"message": "Test operation in the provided patch failed. At path '{path}' expected '{expected}', actual: '{actual}'",
"context": {
"operation": <operation_object>,
"actual-value": <actual>
}
After changes an invalid language code is used422"code": "patched-descriptions-invalid-language-code"
"message": "Not a valid language code '{language_code}' in changed descriptions"
"context": {
"language": <language_code>
}
After changes a description is invalid (empty, too long)422"code": "patched-description-empty"/"patched-description-too-long"
"message": "Changed description for '{lang_code}' cannot be empty" / "Changed description for '{lang_code}' must not be more than '{limit}' characters long"
"context": {
"language": <language_code>
"value": <label> (too long description case only)
"character-limit": <limit> (too long description case only)
}
After changes a description is invalid (not allowed characters used)422"code": "patched-description-invalid"
"message": "Changed description for '{lang_code}' is not valid; '{description-text}'"
"context": {
"language": <language_code>
"value": <description>
}
After changes the item has the exact same label and description in a given language422"code": "patched-item-label-description-same-value"
"message": "Label and description for language code {language} can not have the same value.
"context": {
"language": <language>
}
After changes the item has the same description and label in a given language as an existing item422"code": "patched-item-description-label-duplicate"
"message": "Item {dupe_id} already has description {description}" associated with language code {language}, using the same label."
"context": {
"language": <language>
"label": <label>
"description": <description>
"matching-item-id": <dupe_item_id>
}

Notes:

Related Objects

Event Timeline

Restricted Application added a subscriber: Aklapper. ยท View Herald TranscriptMay 24 2023, 8:27 AM
WMDE-leszek renamed this task from Modify data of descriptions of an item to Modify data of aliases of an item.May 24 2023, 9:10 AM
WMDE-leszek updated the task description. (Show Details)
WMDE-leszek renamed this task from Modify data of aliases of an item to Modify data of descriptions of an item.May 24 2023, 9:18 AM
WMDE-leszek updated the task description. (Show Details)
Silvan_WMDE set the point value for this task to 13.May 24 2023, 9:41 AM
Silvan_WMDE added a project: Story.

Notes from task breakdown:
Subtasks:

  • Add PATCH item descriptions route to OAS doc
  • Create PatchItemDescriptions happy path (empty edit summary)
  • Handle edit metadata (bot flag, tags)
  • Authorization
  • Generate the expected edit summary - language codes are to be sorted alphabetically
  • Validate user input (the patch document, item id, edit metadata)
  • Handle errors that occur while patching the descriptions (test condition, addressing fields that don't exist, ...)
  • Validate the patched descriptions (similar to PatchedLabelsValidator)
    • handles all cases where the patched JSON structure cannot be deserialized into a valid description TermList (empty description, description too long, description containing invalid characters, language code)
    • Collision detection (checking that no other item has the same combination of label and description in any changed language)
    • Check that no changed description is now the same as the label in any changed language
  • Respond 404/409 if item not found or redirected
  • Use the usual middlewares
  • Add OpenAPI validation test
  • Mark as production ready
Ollie.Shotton_WMDE renamed this task from Modify data of descriptions of an item to ๐Ÿฆž Modify data of descriptions of an item.Sep 19 2023, 2:38 PM

Change 961835 had a related patch set uploaded (by Ollie Shotton; author: Ollie Shotton):

[mediawiki/extensions/Wikibase@master] REST: Add metadata to PatchItemDescriptionsResponse

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

Change 961835 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] REST: Add metadata to PatchItemDescriptionsResponse

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

Open questions to this after product verification:

After changes a description is invalid (not allowed characters used): What does this entail exactly? I added a word in the Devanagari script and used a Cyrillic alphabet under "/en" and both worked perfectly. This shouldn't work as far as I understand

After changes an invalid language code is used: Also not sure how I can test this?

@Ifrahkhanyaree_WMDE Regarding testing After changes an invalid language code is used it can be tested by the following patch request:

{
	"patch": [
		{
			"op": "add",
			"path": "/e3",
			"value": "there is no language code like e3"
		}
	],
	"comment": "my first patch request"
}

And regarding After changes a description is invalid (not allowed characters used), as far as I understand, it's related to using a wrong characters inside the description that is modified, for example, to use a number instead of a text, or if the description contained special characters like \t or \n, something like this:

{
	"patch": [
		{
			"op": "add",
			"path": "/en",
			"value": "invalid \n description"
		}
	],
	"comment": "my first patch request"
}

But using a valid text in a different language is valid AFAIK, because I don't remember that we check for such cases.

I was doing it with replace and completely forgot there's other operations of course ยฏ\_(ใƒ„)_/ยฏ

Hmm, I'll move the ticket to Done but I'll ask the question about using different scripts in the daily on Wed.

Thanks!

@Ifrahkhanyaree_WMDE Wikibase does not validate the script used in labels/descriptions/aliases. There might be cases when that wouldn't be desired. And while it would make sense in some obvious cases it might not be a trivial mechanism to create. In any case, adding this kind of validation is something outside of API's responsibilities, i.e. it should be a policy/restriction/safety that Wikibase generally employs.

Yes yes of course, it's something WD would have to do but I was just wondering why the validation didn't exist. I can only imagine that it must be complex