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

Painless: ensure type "UnmodifiableMap" for params #13885

Merged
merged 1 commit into from
Jun 3, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Allow clearing `remote_store.compatibility_mode` setting ([#13646](https://github.com/opensearch-project/OpenSearch/pull/13646))
- Fix ReplicaShardBatchAllocator to batch shards without duplicates ([#13710](https://github.com/opensearch-project/OpenSearch/pull/13710))
- Don't return negative scores from `multi_match` query with `cross_fields` type ([#13829](https://github.com/opensearch-project/OpenSearch/pull/13829))
- Painless: ensure type "UnmodifiableMap" for params ([#13885](https://github.com/opensearch-project/OpenSearch/pull/13885))
- Pass parent filter to inner hit query ([#13903](https://github.com/opensearch-project/OpenSearch/pull/13903))
- Fix NPE on restore searchable snapshot ([#13911](https://github.com/opensearch-project/OpenSearch/pull/13911))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,9 @@ public void testInvalidAssignment() {
assertEquals(iae.getMessage(), "invalid assignment: cannot assign a value to addition operation [+]");
iae = expectScriptThrows(IllegalArgumentException.class, () -> exec("Double.x() = 1;"));
assertEquals(iae.getMessage(), "invalid assignment: cannot assign a value to method call [x/0]");

expectScriptThrows(UnsupportedOperationException.class, () -> exec("params['modifyingParamsMap'] = 2;"));
dblock marked this conversation as resolved.
Show resolved Hide resolved
expectScriptThrows(UnsupportedOperationException.class, () -> exec("params.modifyingParamsMap = 2;"));
}

public void testCannotResolveSymbol() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,50 @@
- match: { error.root_cause.0.position.offset: 13 }
- match: { error.root_cause.0.position.start: 0 }
- match: { error.root_cause.0.position.end: 38 }

---
"Test modifying params map from script leads to exception":
- skip:
features: "node_selector"

- do:
put_script:
id: "except"
body: {"script": {"lang": "painless", "source": "params.that = 3"}}

- do:
indices.create:
index: "test"
body:
settings:
index:
number_of_shards: 1
number_of_replicas: 0
mappings:
properties:
this:
type: "integer"
that:
type: "integer"

- do:
index:
index: "test"
id: 1
body: {"this": 1, "that": 2}

- do:
catch: /unsupported_operation_exception/
node_selector:
version: "2.15.0 - "
update:
index: "test"
id: 1
body:
script:
id: "except"
params: {"this": 2}

- match: { error.caused_by.position.offset: 6 }
- match: { error.caused_by.position.start: 0 }
- match: { error.caused_by.position.end: 15 }
2 changes: 1 addition & 1 deletion server/src/main/java/org/opensearch/script/Script.java
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ public Script(StreamInput in) throws IOException {
@SuppressWarnings("unchecked")
Map<String, String> options = (Map<String, String>) (Map) in.readMap();
this.options = options;
this.params = in.readMap();
this.params = Collections.unmodifiableMap(in.readMap());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

package org.opensearch.script;

import java.util.Collections;
import java.util.Map;

/**
Expand All @@ -53,7 +54,7 @@ public abstract class UpdateScript {
private final Map<String, Object> ctx;

public UpdateScript(Map<String, Object> params, Map<String, Object> ctx) {
this.params = params;
this.params = Collections.unmodifiableMap(params);
this.ctx = ctx;
}

Expand Down
Loading