Skip to content

Commit

Permalink
Prevent Index#delete with empty string.
Browse files Browse the repository at this point in the history
Add a safe guard to not call ES client delete with an empty string.
Bug introduced with toptal#735
  • Loading branch information
Bhacaz committed Jan 29, 2021
1 parent fc737a4 commit b56a06a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# master

* [#739](https://github.com/toptal/chewy/pull/739): Remove explicit `main` branch dependencies on rspec* gems after `rspec-mocks` 3.10.2 is released ([@rabotyaga][])
* [#740](https://github.com/toptal/chewy/pull/740): Prevent calling Index#delete with an empty string. ([@bhacaz][])

# Version 5.2.0 (2021-01-28)

Expand Down
5 changes: 3 additions & 2 deletions lib/chewy/index/actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ def delete(suffix = nil)
# "The index parameter in the delete index API no longer accepts alias names.
# Instead, it accepts only index names (or wildcards which will expand to matching indices)."
# https://www.elastic.co/guide/en/elasticsearch/reference/6.8/breaking-changes-6.0.html#_delete_index_api_resolves_indices_expressions_only_against_indices
index_names = client.indices.get_alias(index: index_name(suffix: suffix)).keys
result = client.indices.delete index: index_names.join(',')
index_name_to_delete = index_name(suffix: suffix)
index_names = client.indices.get_alias(index: index_name_to_delete).join(',').presence || index_name_to_delete
result = client.indices.delete index: index_names
Chewy.wait_for_status if result
result
# es-ruby >= 1.0.10 handles Elasticsearch::Transport::Transport::Errors::NotFound
Expand Down
1 change: 1 addition & 0 deletions spec/chewy/index/actions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
context do
before { DummiesIndex.delete }
specify { expect(Chewy.client.indices.exists(index: 'dummies')).to eq(false) }
specify { expect(DummiesIndex.delete).to eq(false) }
end
end

Expand Down

0 comments on commit b56a06a

Please sign in to comment.