Page MenuHomePhabricator

Changing or reordering field values causes value reassignment for existing tasks
Closed, ResolvedPublic

Description

Reordering values for a field or inserting new ones into the order reassigns the values with associated tasks. It seems that field values for tasks are associated with the index of the field value and not the value itself. So if we have a field, "Versions" with values:

B
C
D

And we add a new value A at the beginning of the Versions list to make,

A
B
C
D

Then every task that had previously had Version = B now have Version = A. Tasks where Version = C become Version = B, and so on. This happens if we add values anywhere in the list. The only workaround is appending to the end.

We need to be able to reorder, insert and remove values from field options and have the values for existing tasks remain as they were

Event Timeline

tobias raised the priority of this task from to High.
tobias updated the task description. (Show Details)
tobias added a project: Maniphest.
tobias added a subscriber: tobias.

Is this with a custom select field?

My guess is that the field is specified like this:

"example:versions": {
  "name": "Version",
  "type": "select",
  "options": ["A", "B", "C"]
}

If you use an object/map to specify the options instead of an array, you can choose the keys the options uses:

"example:versions": {
  "name": "Version",
  "type": "select",
  "options": {
    "A": "A",
    "B": "B",
    "C": "C"
  }
}

That should let you add, remove, and reorder values safely.

Assuming I'm right, you can swap by using numeric keys, e.g. change this:

["A", "B", "C"]

...to this:

{
  "0": "A",
  "1": "B",
  "2": "C"
}

That won't change any of the existing values (since we store 0/1/2 in the database), and you can then freely adjust the map from there.

yep you're right. Thanks! Is there a way to migrate to the new structure without losing all the data in existing fields?

The current structure has implicit keys "0", "1", "2", etc, so you can just make those implicit keys explicit. For example, change this:

["A", "B", "C"]

...to this:

{
  "0": "A",
  "1": "B",
  "2": "C"
}

If you browse around after making that change, all the data should still look the same.

Then you can add and rearrange keys freely. They don't need to go in a specific order or follow the same sequence. For example, if you add a new value with a more verbose key:

{
  "0": "A",
  "versionD": "versionD",
  "1": "B",
  "2": "C"
}

...that should not affect existing things with values "A", "B" or "C".

tobias claimed this task.

That did it. Thanks so much

Cool, let us know if you run into anything else.