From 4a1b9977cd7bb1d5227074863817e2c08305e38f Mon Sep 17 00:00:00 2001 From: Caio <117518+caiosba@users.noreply.github.com> Date: Thu, 14 Sep 2023 12:17:15 -0300 Subject: [PATCH] Do not crash when calculating number of items in a list that has an invalid 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. --- lib/check_search.rb | 4 ++-- test/models/saved_search_test.rb | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/check_search.rb b/lib/check_search.rb index a2d77c1c35..eefe0d25fd 100644 --- a/lib/check_search.rb +++ b/lib/check_search.rb @@ -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') diff --git a/test/models/saved_search_test.rb b/test/models/saved_search_test.rb index 4b74a28bbf..2980963db1 100644 --- a/test/models/saved_search_test.rb +++ b/test/models/saved_search_test.rb @@ -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