Opened 2 years ago

Closed 2 years ago

# Custom queries broken when using "contains" with a multi-select custom field

Reported by: Owned by: jbeilicke cmc normal MultiSelectCustomFieldsPatch normal 0.12

### Description

Attached please find a modified version of the original patch that fixes the mentioned issue in Trac 0.12. The bug in ticket/query.py line 545 lead to wrong database results, due to a pipe right before the last percentage:

Original patch:

value = '%' + value + '|%'


Modified version:

value = '%' + value + '%'


### comment:1 follow-up: ↓ 2 Changed 2 years ago by cmc

• Resolution set to invalid
• Status changed from new to closed

That is not correct. All multi-select values should end with a pipe. Hence, '%' + value + '%' may actually return incorrect result.

Imagine if options were 'Dog' and 'Dog Park'. If you searched for 'Dog', a ticket with 'Dog Park' (in the database, 'Dog Park|') would come up with your proposed change. Instead, if you search for '%Dog|%', no Dog Park entries will be returned.

### comment:2 in reply to: ↑ 1 ; follow-up: ↓ 3 Changed 2 years ago by jbeilicke

That is not correct. All multi-select values should end with a pipe. Hence, '%' + value + '%' may actually return incorrect result.

You are right, of course. Quite obvious, but I didn't see this. Thanks for the clarification. I will revert my patch and check again why the queries with multi-selects are not working as expected. :)

### comment:3 in reply to: ↑ 2 ; follow-up: ↓ 4 Changed 2 years ago by cmc

That is not correct. All multi-select values should end with a pipe. Hence, '%' + value + '%' may actually return incorrect result.

You are right, of course. Quite obvious, but I didn't see this. Thanks for the clarification. I will revert my patch and check again why the queries with multi-selects are not working as expected. :)

Mind you, this patch was originally written for 0.11 and I haven't worked on the 0.12 version for a year. I wouldn't be at all surprised if there was a bug somewhere else ;) Are the fields savings with pipes? If you're converting an existing field over to use multi-select, you'll need to append a pipe to each value.

### comment:4 in reply to: ↑ 3 Changed 2 years ago by jbeilicke

That is not correct. All multi-select values should end with a pipe. Hence, '%' + value + '%' may actually return incorrect result.

You are right, of course. Quite obvious, but I didn't see this. Thanks for the clarification. I will revert my patch and check again why the queries with multi-selects are not working as expected. :)

Mind you, this patch was originally written for 0.11 and I haven't worked on the 0.12 version for a year. I wouldn't be at all surprised if there was a bug somewhere else ;) Are the fields savings with pipes? If you're converting an existing field over to use multi-select, you'll need to append a pipe to each value.

That is the case: I have to append the pipe. Thanks again.

### Modify Ticket

Change Properties