Opened 5 years ago

Closed 3 years ago

Pipe is not appended to single option

Reported by: Owned by: Jan Beilicke CM Lubinski normal MultiSelectCustomFieldsPatch normal 0.12

Description

I just noticed that some queries didn't return all matching tickets. At first I thought it might be caused by old data, that was not updated (see also #9731). It turned out, that every update to a ticket (ticket properties or comments) removes the pipe of single options again.

When the multi had more than one selected options (which worked fine) and all but one options are removed, the remaining option is stored without a pipe.

I assume that the pipe is simply not set in the model.py __setitem__() where isinstance(value, list) is processed - maybe the value isn't a list anymore?

Feedback is highly appreciated. :)

comment:1 Changed 5 years ago by Jan Beilicke

Summary: Pipe is not appended for single options → Pipe is not appended to single option

After some investigation I came up with the following patch. It contains the original MultiSelectPatch (only model.py) plus a quick fix for my issue, applied in populate():

• ticket/model.py

 old def __setitem__(self, name, value): """Log ticket modifications so the table ticket_change can be updated """ if isinstance(value, list): #   account for multi-selects value = '|'.join(value) + '|' if name in self.values and self.values[name] == value: return if name not in self._old: # Changed field del self._old[name] if value: if isinstance(value, list): raise TracError(_("Multi-values fields not supported yet")) value = '|'.join(value) + '|' field = [field for field in self.fields if field['name'] == name] if field and field[0].get('type') != 'textarea': value = value.strip() field_names = [f['name'] for f in self.fields] for name in [name for name in values.keys() if name in field_names]: self[name] = values.get(name, '') # We have to do an extra trick to catch unchecked checkboxes for name in [name for name in values.keys() if name[9:] in field_names and name.startswith('checkbox_')]: if name[9:] not in values: self[name[9:]] = '0' for f in self.fields: # We do something similar for empty multi-selects if f['type'] == 'multi' and not f['name'] in values: self[f['name']] = '' # Single multi values should be lists, too. elif f['type'] == 'multi' and f['name'] in values: if not isinstance(values[f['name']], list): self[f['name']] = [values[f['name']]] def insert(self, when=None, db=None): """Add ticket to database.

So far it seems to work, the pipe gets (and stays) appended to single values.

comment:2 Changed 3 years ago by Ryan J Ollos

Resolution: → wontfix new → closed

TracMultiSelectBoxPlugin is pretty good. I'm going to mark this plugin as deprecated in favor of that one, or MultiSelectFieldPlugin, which I haven't looked at.

Last edited 3 years ago by Ryan J Ollos (previous) (diff)

Modify Ticket

Action
as closed The owner will remain CM Lubinski.
The resolution will be deleted. Next status will be 'reopened'.