Skip to content

Commit

Permalink
Fix watcher check that determines when to serialize indices options. (#…
Browse files Browse the repository at this point in the history
…78165)

Backporting #78070 to 7.x branch.

The check was an identity check between the default constant and
the set indices options. This check is incorrect because in many
cases when `IndicesOptions` is parsed or randomly generated in tests,
then this check incorrectly returns false when in fact an `IndicesOptions`
instance is equal to the default constant, but it is just a different
instance/object.

Closes #78035
  • Loading branch information
martijnvg authored Sep 22, 2021
1 parent 67fb3b8 commit 8e58c01
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
builder.rawField(BODY_FIELD.getPreferredName(), stream);
}
}
if (indicesOptions != DEFAULT_INDICES_OPTIONS) {
if (indicesOptions.equals(DEFAULT_INDICES_OPTIONS) == false) {
builder.startObject(INDICES_OPTIONS_FIELD.getPreferredName());
indicesOptions.toXContent(builder, params);
builder.endObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ public void testSerializeSearchRequest() throws Exception {
assertThat(result.getTemplate().getIdOrCode(), equalTo(expectedSource.utf8ToString()));
assertThat(result.getTemplate().getType(), equalTo(ScriptType.INLINE));
}
if (expectedIndicesOptions != DEFAULT_INDICES_OPTIONS && expectedTypes != null) {
if (expectedIndicesOptions.equals(DEFAULT_INDICES_OPTIONS) == false && expectedTypes != null) {
assertWarnings(IGNORE_THROTTLED_FIELD_WARNING, WatcherSearchTemplateRequest.TYPES_DEPRECATION_MESSAGE);
assertThat(result.getTypes(), arrayContainingInAnyOrder(expectedTypes));
} else if (expectedIndicesOptions != DEFAULT_INDICES_OPTIONS) {
} else if (expectedIndicesOptions.equals(DEFAULT_INDICES_OPTIONS) == false) {
assertWarnings(IGNORE_THROTTLED_FIELD_WARNING);
} else if (expectedTypes != null) {
assertWarnings(WatcherSearchTemplateRequest.TYPES_DEPRECATION_MESSAGE);
Expand Down

0 comments on commit 8e58c01

Please sign in to comment.