Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not crash when calculating number of items in a list that has an invalid team task filter #1653

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you remove @options.has_key?('team_tasks') from unless condition?
I think we should keep it and only update delete_if to include tt['id'].blank?

Copy link
Contributor Author

@caiosba caiosba Sep 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@melsawy because I think it's redundant with @options['team_tasks'].class.name ... if there is no team_tasks key, @options['team_tasks'].class.name is going to return NilClass

@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
Loading