Skip to content

Commit

Permalink
Do not crash when calculating number of items in a list that has an i…
Browse files Browse the repository at this point in the history
…nvalid team task filter

I noticed it happening on live only for duplicated workspaces. When a list has a team task filter that doesn't have a valid ID, an exception would happen. I was able to reproduce that exception in a unit test.

The fix was to discard the team task filter if the ID is blank.

Fixes CV2-3742.
  • Loading branch information
caiosba authored Sep 14, 2023
1 parent 8a9a02b commit 982df0d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/check_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,8 @@ def file_filter

def team_tasks_conditions
conditions = []
return conditions unless @options.has_key?('team_tasks') && @options['team_tasks'].class.name == 'Array'
@options['team_tasks'].delete_if{ |tt| tt['response'].blank? }
return conditions unless @options['team_tasks'].class.name == 'Array'
@options['team_tasks'].delete_if{ |tt| tt['response'].blank? || tt['id'].blank? }
@options['team_tasks'].each do |tt|
must_c = []
must_c << { term: { "task_responses.team_task_id": tt['id'] } } if tt.has_key?('id')
Expand Down
7 changes: 7 additions & 0 deletions test/models/saved_search_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,11 @@ def setup
ss = create_saved_search
assert_equal 0, ss.items_count
end

test "should not crash if filter is invalid" do
ss = create_saved_search filters: { team_tasks: [{ id: '', task_type: 'single_choice', response: 'NO_VALUE' }] }
assert_nothing_raised do
assert_equal 0, ss.items_count
end
end
end

0 comments on commit 982df0d

Please sign in to comment.