The DataItem.choices attribute contains a list of tuple containing key value pairs (list[tuple[str, str]] in most cases). When we need a value, we parse this list to find the corresponding key. However, there are some instances where we parse the list and check the values to get the corresponding keys. This is a problem when several keys point to duplicate values (e.g. two projects of the same name) as we never check for duplicate value. This behavior also prevents the addition of new color that would have the same first letter.
The root of the issue is located in the DataItem.from_text, DataItem.to_text and DataItem.from_display.
Proposed improvements/solutions could be:
The
DataItem.choicesattribute contains a list of tuple containing key value pairs (list[tuple[str, str]]in most cases). When we need a value, we parse this list to find the corresponding key. However, there are some instances where we parse the list and check the values to get the corresponding keys. This is a problem when several keys point to duplicate values (e.g. two projects of the same name) as we never check for duplicate value. This behavior also prevents the addition of new color that would have the same first letter.The root of the issue is located in the
DataItem.from_text,DataItem.to_textandDataItem.from_display.Proposed improvements/solutions could be:
DataItem.from_displayDataItem.to_textis called both to set the display value and the value to write in the XML. This method returns the choices values instead of the keys which forces us to match the values to get back the keys when reopening the XML file.