Skip to content

Commit 5f8c653

Browse files
authored
[Transform] Fix NPE that is thrown by _update API (elastic#104051) (elastic#104057)
1 parent 42518dc commit 5f8c653

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

docs/changelog/104051.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 104051
2+
summary: Fix NPE that is thrown by `_update` API
3+
area: Transform
4+
type: bug
5+
issues:
6+
- 104048

x-pack/plugin/transform/qa/single-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/transform/integration/TransformDestIndexIT.java

+11-3
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,16 @@ public void testTransformDestIndexAliases() throws Exception {
109109
assertAliases(destIndex2, destAliasAll, destAliasLatest);
110110
}
111111

112-
public void testTransformDestIndexCreatedDuringUpdate() throws Exception {
113-
String transformId = "test_dest_index_on_update";
112+
public void testTransformDestIndexCreatedDuringUpdate_NoDeferValidation() throws Exception {
113+
testTransformDestIndexCreatedDuringUpdate(false);
114+
}
115+
116+
public void testTransformDestIndexCreatedDuringUpdate_DeferValidation() throws Exception {
117+
testTransformDestIndexCreatedDuringUpdate(true);
118+
}
119+
120+
private void testTransformDestIndexCreatedDuringUpdate(boolean deferValidation) throws Exception {
121+
String transformId = "test_dest_index_on_update" + (deferValidation ? "-defer" : "");
114122
String destIndex = transformId + "-dest";
115123

116124
assertFalse(indexExists(destIndex));
@@ -134,7 +142,7 @@ public void testTransformDestIndexCreatedDuringUpdate() throws Exception {
134142
// Note that at this point the destination index could have already been created by the indexing process of the running transform
135143
// but the update code should cope with this situation.
136144
updateTransform(transformId, """
137-
{ "settings": { "max_page_search_size": 123 } }""");
145+
{ "settings": { "max_page_search_size": 123 } }""", deferValidation);
138146

139147
// Verify that the destination index now exists
140148
assertTrue(indexExists(destIndex));

x-pack/plugin/transform/qa/single-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/transform/integration/TransformRestTestCase.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -399,13 +399,16 @@ protected void createPivotReviewsTransform(String transformId, String transformI
399399
createPivotReviewsTransform(transformId, transformIndex, query, pipeline, null, null, authHeader, null, REVIEWS_INDEX_NAME);
400400
}
401401

402-
protected void updateTransform(String transformId, String update) throws IOException {
402+
protected void updateTransform(String transformId, String update, boolean deferValidation) throws IOException {
403403
final Request updateTransformRequest = createRequestWithSecondaryAuth(
404404
"POST",
405405
getTransformEndpoint() + transformId + "/_update",
406406
null,
407407
null
408408
);
409+
if (deferValidation) {
410+
updateTransformRequest.addParameter("defer_validation", String.valueOf(deferValidation));
411+
}
409412
updateTransformRequest.setJsonEntity(update);
410413

411414
client().performRequest(updateTransformRequest);

x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/action/TransportValidateTransformAction.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
import java.util.Map;
4040

41+
import static java.util.Collections.emptyMap;
4142
import static org.elasticsearch.core.Strings.format;
4243

4344
public class TransportValidateTransformAction extends HandledTransportAction<Request, Response> {
@@ -127,7 +128,7 @@ protected void doExecute(Task task, Request request, ActionListener<Response> li
127128
// <4> Deduce destination index mappings
128129
ActionListener<Boolean> validateQueryListener = ActionListener.wrap(validateQueryResponse -> {
129130
if (request.isDeferValidation()) {
130-
deduceMappingsListener.onResponse(null);
131+
deduceMappingsListener.onResponse(emptyMap());
131132
} else {
132133
function.deduceMappings(client, config.getHeaders(), config.getSource(), deduceMappingsListener);
133134
}

0 commit comments

Comments
 (0)