Page MenuHomePhabricator

Unexpected list diff api endpoint behavior when diffing lists of tools
Closed, ResolvedPublicBUG REPORT

Description

Some edits to the list of tools that modify the indices of the remaining items in the list result in unexpected behavior of the /api/lists/{list_pk}/revisions/{id}/diff/{other_id}/ endpoint.

Example:

  1. Initial list [tool1, tool2, tool3]
  2. Remove tool1 and tool2
  3. Updated list is now [tool3]

The api returns the following operations:

"operations": [
  {
    "op": "remove",
    "path": "/tools/0"
  },
  {
    "op": "remove",
    "path": "/tools/0"
  }
],
Expected behavior:
  "operations": [
    {
      "op": "remove",
      "path": "/tools/0"
    },
    {
      "op": "remove",
      "path": "/tools/1"
    }
  ],
}

There is a certain "logic" behind this behavior if you consider the operations as sequential, i.e. when the first tool at index 0 is removed, the new index of the second tool now becomes 0. So, it makes sense for the second remove op to also happen at index 0 as this is where the (previously) second tool moves to after the first remove op.

This behavior probably stems from the library that is used to generate the diffs, jsonpatch.

Event Timeline

The user facing bug here is less how jsonpatch works and more how our visualization of the patch as a diff is rendered. Our existing code does not apply the patch elements to the basis record which in turn means that when we lookup the value of a pointer like "/tools/0" we always return the initial 0th index value even if there have been multiple instructions in the patch previously that would have mutated the "tools" array.

Changing how jsonpatch works is not easily in scope, but we can try to fix up the code that we use to create the visual display. This may be easier to accomplish following the work being done for T301206: Structured diff UI assumes all members are scalars or arrays.

Change 762476 had a related patch set uploaded (by BryanDavis; author: Bryan Davis):

[wikimedia/toolhub@main] ui: Refactor and update diff rendering behavior

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

bd808 changed the task status from Open to In Progress.Feb 18 2022, 7:03 PM
bd808 claimed this task.
bd808 triaged this task as Medium priority.
bd808 moved this task from Backlog to Review on the Toolhub board.

Change 762476 merged by jenkins-bot:

[wikimedia/toolhub@main] ui: Refactor and update diff rendering behavior

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

Change 770638 had a related patch set uploaded (by BryanDavis; author: Bryan Davis):

[operations/deployment-charts@master] toolhub: Bump container version to 2022-03-15-002555-production

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

Change 770638 merged by jenkins-bot:

[operations/deployment-charts@master] toolhub: Bump container version to 2022-03-15-002555-production

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